[Twisted-Python] twisted.web, url -> resource mapping and isLeaf questions
david at silveregg.co.jp
Tue Nov 30 01:07:17 EST 2010
I am following "twisted in 60sec" series, but even the simple examples
are a bit unclear to me, especially w.r.t. url mapping. For example:
# assume the right imports...
isLeaf = True
def render_GET(self, request):
resource = MainPage()
factory = Site(resource)
I was expecting that accessing any other 'path' besides the main url
would cause 404, e.g. "http://localhost:8880/foo/bar", and I get the
same page instead.
I gather this is a consequence of the isLeaf setting set to be True,
because twisted.web stops as soon as it encounters MainPage in the
hierarchy and use that for rendering. Setting it to False seems to avoid
the page to be available at all. The solution I got instead is something
isLeaf = False
def render(self, request):
def getChild(self, path, request):
and adding new resources through putChild. Isn't there a more natural
way of doing things ?
More information about the Twisted-Python