[mod_python] Session Management, Straight Answer?

Graham Dumpleton grahamd at dscpl.com.au
Tue May 16 00:23:13 EDT 2006


Max Lynch wrote ..
> I have looked at many of the session management posts on the list, but
> I am looking for a straightforward answer on how to make session data persist
> through different pages.  I have seen examples on using cookies/etc., but
> I would like a formal answer as it seems many people are also stuck on
> this (I might post my experiences with mod_python on a site as first-hand
> documentation, so that could help).  Also, I am using psp, not the publisher
> stuff.  Love mod_python so far though, just a little stuck!

If you are using psp only (not combined with publisher), then all you
need to do is access "session" attribute from a page and the session
object will be automatically created for you. The session object will
also be automatically saved for you after page has rendered.

This is mentioned in the documentation:

  http://www.modpython.org/live/current/doc-html/pyapi-psp.html

  Additionally, the PSP code will be given global variables req, psp,
  session and form. A session will be created and assigned to session
  variable only if session is referenced in the code (the PSP handler
  examines co_names of the code object to make that determination).
  Remember that a mere mention of session will generate cookies and turn
  on session locking, which may or may not be what you want. Similarly, a
  mod_python FieldStorage object will be instantiated if form is
  referenced in the code.

If you were aware of this, what is the actual problem you are having?

Graham


More information about the Mod_python mailing list