[Twisted-web] [Nevow] childFactory being called more than once

Valentino Volonghi aka Dialtone dialtone at divmod.com
Wed Feb 21 04:58:05 CST 2007

On Wed, 21 Feb 2007 11:19:41 +0100, Manlio Perillo <manlio_perillo at libero.it> wrote:
>Just forget it!
>I have a personalized locateChild in the base class, where I do:
>     def locateChild(self, ctx, segments):
>         request = inevow.IRequest(ctx)
>         if request.args.get('login-failure'):
>             import login
>             return login.Login(self.avatar, failure=True), ''
>         res = rend.Page.locateChild(self, ctx, segments)
>         if res == rend.NotFound:
>             return NotFound(self.avatar), ''
>         return rend.Page.locateChild(self, ctx, segments) # <===

This code is wrong in 2 ways:

1) locateChild can return deferreds, you are not covering this aspect.
2) Why calling locateChild twice when once is enough? if the page is not rend.NotFound then it's the page you want... just return it.

>By the way, is this code the best way to handle a login failure?

Can't spot anything terribly wrong there.

>Moreover, I still do not understand why, when replacing macro with render, 
>locateChild is called 3 times, instead of 2.

You probably have other confusions in your source. As I said there's no link _at all_ between rendering and child locating.

More information about the Twisted-web mailing list