[Twisted-web] Cannot redirect to a SessionWrapper-wrapped page (example code included)

kgi iacovou at gmail.com
Mon Jul 16 11:01:14 EDT 2007

On Monday 16 July 2007 17:11:25 glyph at divmod.com wrote:
> The guard wrapper is being re-created on every hit in the child_foopage
> method.  So, the session storage is getting re-created on every hit,
> which means that your session isn't being stored anywhere that the
> resource can access it.  So each time the browser hits it, it tries to
> recreate its session.
> Put the guard wrapper somewhere persistent so that it will be the *same*
> guard wrapper accessed on subsequent hits, and it will work.

Yes, that's it; thanks Glyph.

Actually, while we're on the subject, there's one more oddity. It's not 
terribly important for reasons I'll describe below, but it's still something 
that confuses me.

If I patch the file in my previous attachment to create and reuse a single 
persistent guard wrapper, like this:

class TopLevel ( rend.Page ):

    def __init__ ( self ):
        rend.Page.__init__ ( self )
	self.gresource = createGuardedResource()


    def child_foopage ( self, ctx ):
        return self.gresource

... then the looping disappears BUT I get the "cannot render livepage more 
than once" error. The way to overcome this seems to be to uncomment 
the "child_()" method in FooPage():

    def child_ ( self, ctx ):
        return FooPage()

... so that any attempt to access the path of the LivePage afresh will get a 
new instance of the page. I want this behaviour anyway, because I don't want 
browser refreshes to throw up an error.

However, I'm confused as to why this error would occur the FIRST time I access 
the LivePage after GuardWrapper authentication. As far as I can tell, I've 
just rendered the page once.



More information about the Twisted-web mailing list