[Twisted-Python] sessions example
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. That would be very helpful, thanks, _stephan
stephan <mailinglists@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.
Stephan, I found the following link helpful: http://twistedmatrix.com/documents/howto/picturepile#auto2 stephan wrote:
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.
That would be very helpful, thanks,
_stephan
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- * Martin C. Stoufer * * DIDC/DSD/ITG * * Lawrence Berkeley National Lab * * MS 50B-2215 510-486-8662 *
participants (3)
-
Martin Stoufer
-
stephan
-
Syver Enstad