[Twisted-web] Nevow: How to use sessions?

Mohamed Lrhazi mohamed at your-site.com
Tue Dec 14 07:24:15 MST 2004


Hello all,

Can someone give a helloworld example of how to store and retrieve objects 
specific to a session ? maybe a counter example. The objects would need to 
be destroyed automatically when the session expires.

In the examples I see things like:

def setupSession(self, ctx):
        #need to place the user, usermanager in the session
        inevow.ISession(ctx).setComponent(ICurrentUser, self.user)
        inevow.ISession(ctx).setComponent(IUserManager, self.userManager)
and

self.userManager = request.session.getComponent(IUserManager)

Can I just do that to store any object? do I have to create an interface 
for it?

When I looked for more in the source all I found was:

class ISession(compy.Interface):
    """A web session

    You can locate a Session object to represent a unique web session using
    ctx.locate(ISession). This default session implementation uses cookies 
to
    store a session identifier in the user's browser.

    TODO: Need better docs; what's a session and why and how do you use it
    """

Thanks a lot.
Mohamed~



More information about the Twisted-web mailing list