[Twisted-web] Returning an HTTP error from render method

Jonathan Blocksom jblocksom at gsti3d.com
Wed Jun 22 10:13:41 MDT 2005

Hi, I'm trying to figure out how to return an HTTP error in the render 
method of a custom Resource.  I can't find any docs on it, but from 
poking around in the code I came up with the code below that doesn't do 
it.  Can somebody point me in the right direction for returning an error 
from the render method?  Or should I be returning the error somewhere else?



from twisted.web import server
from twisted.internet import reactor
from twisted.web.resource import Resource

class Sample404(Resource):
     "Returns a 404 error for everything except /hello"

     isLeaf = True
     def render_GET(self, request):
         if (request.path != '/hello'):
             return server.NOT_DONE_YET
             return "<html>You found me!</html>"

if __name__=='__main__':
     site = server.Site(Sample404())

     reactor.listenTCP(8080, site)

More information about the Twisted-web mailing list