[mod_python] Publisher + PSP + Sessions?

Fredrik Sandin fredrik.sandin at ltu.se
Tue Aug 29 16:53:57 EDT 2006


Given the following configuration

<Directory "...">
     SetHandler mod_python
     PythonHandler mod_python.publisher

and a template loading meachanism similar to the one in
the example on the modpython homepage:


how to access the session (dictionary) outside the psp

Within a psp template it is possible to write

if not session.has_key('myvar'):
     session['myvar'] = 0 # Default value

However, since the idea is to separate the template from
the logic, I would prefer to do this in the python function.
Example, inside myhandler.py:

def index(req):
     if not X.has_key('myvar'):
         X['myvar'] = 0 # Default value
     return _build_page(req, template='index')

How to define X such that session['myvar'] will be defined
inside the psp template for the index page?


More information about the Mod_python mailing list