[Twisted-Python] More problems running examples

Phil Hunt phil.hunt at tech.mrc.ac.uk
Fri Feb 20 07:02:02 EST 2004


OK, I've now been able to get the very simplest webserver running.
I'm trying something slightly more complex, based on the next example
in <Twisted-1.1.1/doc/howto/using-twistedweb.html>.

The Hello class given in the exmaple is not a full program:

#####################################################################
# teg3.py

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 %r.
    </html>"""               % (request.prepath) 

resource = Hello()
#####################################################################

When I run this it exits immediately; I assume this is intentional.

I built on the previous example to produce a full program; my code is:

#####################################################################
# teg2.py

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

class Hello(resource.Resource):

   def getChild(self, name, request):
      if name == '':
         result = self
      else:   
         result = Resource.getChild(self, name, request)
      print "in Hello:getChild, result=%r" % (result,)
      return result

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

print "===== Running teg2.py (simple webserver) ====="
res = Hello()

site = server.Site(res)
reactor.listenTCP(8011, site)
reactor.run()
#####################################################################


Now, this does actually run, however whenever I point my webserver at it,
all that comes back is a 404 error with the text:

   No Such Resource
   No such child resource.

And my program writes to stdout:

   in Hello:getChild, result=<twisted.web.error.NoResource instance at
   0x406adb0c>

-- 
Phil Hunt, phil.hunt at tech.mrc.ac.uk




More information about the Twisted-Python mailing list