[mod_python] Publisher + PSP + Sessions?

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


Hello!

Given the following configuration

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

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

http://www.modpython.org/examples/psp_site/

how to access the session (dictionary) outside the psp
templates?

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?

Cheers,
Fredrik


More information about the Mod_python mailing list