[Twisted-web] I feel like I have a path one-off error here somewhere...

Mark Wright markscottwright at gmail.com
Thu Aug 27 13:24:40 EDT 2009


I'm trying to set up a dynamic tree of resources - a list of resources
that drill-down into individual resources.  But for some reason,
getChild never gets called on my root resource.  The following code
will output a list of ids, but "/id" doesn't call getChild.  What am I
doing wrong?

from twisted.web import server, resource

class Child(resource.Resource):

    def __init__(self, childid):
        self.childid = childid

    def render_GET(self, request):
        return "<h1>" + self.childid + "</h1>"

class Root(resource.Resource):

    def render_GET(self, request):
        pg = ""
        for i in range(10):
            pg += '<p><a href="/' + str(i) + '">' + str(i) + "</a></p>"
        return pg

    def getChild(self, path, request):
        return Child(path)

if __name__ == "__main__":
    from twisted.internet import reactor

    root = resource.Resource()
    root.putChild('', Root())
    site = server.Site(root)
    reactor.listenTCP(8080, site)
    reactor.run()




-- 
Mark Wright
markscottwright at gmail.com



More information about the Twisted-web mailing list