I feel like I have a path one-off error here somewhere...

Mark Wright <[email protected]>
Newsgroups gmane.comp.python.twisted.web
Message-ID <[email protected]>
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
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.