[Twisted-Python] More problems running examples

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@tech.mrc.ac.uk

The code is fine, so I wonder what URL you're pointing the browser at. Tried http://127.0.0.1:8011/ ? Anything else will produce a resource error since res has no child resources. Cheers, Joe

On Friday 20 Feb 2004 12:41 pm, Joe Halliwell wrote:
Yes, it works for http://127.0.0.1:8011/, but as you say, when I use any other URL such as http://127.0.0.1:8011/this/is/a/path/ it doesn't work. What I want to know is how do I make it work with other URLs, and how do I get it to bring up dynamically-produced web pages. Is this what .rpy files are for? IOW, is an .rpy file the equivalent of a .php file in that it contains code for writing one specific web page? -- Phil Hunt, phil.hunt@tech.mrc.ac.uk

On Fri, Feb 20, 2004, Phil Hunt wrote:
These questions should be asked on the twisted-web mailing list: http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web -Mary

The code is fine, so I wonder what URL you're pointing the browser at. Tried http://127.0.0.1:8011/ ? Anything else will produce a resource error since res has no child resources. Cheers, Joe

On Friday 20 Feb 2004 12:41 pm, Joe Halliwell wrote:
Yes, it works for http://127.0.0.1:8011/, but as you say, when I use any other URL such as http://127.0.0.1:8011/this/is/a/path/ it doesn't work. What I want to know is how do I make it work with other URLs, and how do I get it to bring up dynamically-produced web pages. Is this what .rpy files are for? IOW, is an .rpy file the equivalent of a .php file in that it contains code for writing one specific web page? -- Phil Hunt, phil.hunt@tech.mrc.ac.uk

On Fri, Feb 20, 2004, Phil Hunt wrote:
These questions should be asked on the twisted-web mailing list: http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web -Mary
participants (3)
-
Joe Halliwell
-
Mary Gardiner
-
Phil Hunt