[Twisted-Python] Should this example code run?

Stuart Hungerford stuart.hungerford at anu.edu.au
Thu May 8 20:49:26 EDT 2003


Hi all,

I'm working my way through the twisted.web documentation
and came across this snippet (to be saved in a ".rpy" file):



from twisted.web.resource import Resource

class Hello(Resource):
     def getChild(self, name, request):
         if name == '':
             return self
         return Resource.getChild(self, name, request)

         def render(self, request):
             return """<html> Hello, world! I am located at %s. 
</html>"""  % (request.prepath)

resource = Hello()


The original snippet had a "%r" format string which I'm assuming
was meant to be "%s".  When I access this .rpy file twisted web
reports a stack dump with:


web.Server Traceback (most recent call last):

exceptions.NotImplementedError: __builtin__.Hello.render called

/opt/Twisted-1.0.4/twisted/web/server.py, line 153 in process
151    try:
152      resrc = self.site.getResourceFor(self)
153      self.render(resrc)
154    except:
Self
site
twisted.web.server.Site instance @ 0x365110 <twisted.web.server.Site 
instance at 0x365110>
Locals
resrc
__builtin__.Hello instance @ 0x467ec0 <__builtin__.Hello instance at 0x467ec0>
self
twisted.web.server.Request instance @ 0x48c920 <GET /test2.rpy HTTP/1.1>



Can someone enlighten me on the cause of the error?


Cheers,

Stu

--
:: Stuart Hungerford (stuart.hungerford at anu.edu.au)
:: ANU Internet Futures Group





More information about the Twisted-Python mailing list