[Twisted-Python] sessions example

Syver Enstad syver at inout.no
Fri Nov 7 03:12:13 MST 2003


stephan <mailinglists at shechen.at> writes:

> Just by reading the API doc I somehow cannot figure out how to use
> session in the twisted webserver. Would anybody be so kind and give my
> a short example of how to create a session, store some objects in it
> and then retrive the same session again.

class Foo:
    def doStuff(self):
        ....

You have to have the request.

session = request.getSession()
session.foo = Foo()

Now later in your application you can do:

foo = session.foo
foo.doStuff()

If you use the twisted web server for more than one logical
application you should probably do something like this.

class MyApplicationSession:
   .....

session = request.getSession()

session.sessions = {}

session.sessions[MyApplicationSession] = MyApplicationSession()

And something similar but another class for other applications.




 





More information about the Twisted-Python mailing list