[mod_python] Session example and problems.

Shawn Harrison harrison at tbc.net
Thu Feb 24 16:36:43 EST 2005


donnie jones wrote [02/24/05 2:55 PM]:
> Hello,
> 
> Could someone please give me an example of using the Session() 
> in modpython for passing data between functions?  
> I have been googling, but with no success..
> 
> The problem I am having is that each time I reload a page that calls
> the function like below, it creates a new session.
> 
> def test(req):
>   sess = Sess(req);
>   sid = sess.id();
>   if sess.is_new():
>     req.write("new session %s" % sid);
>   else:
>     sess.load();
>     req.write("%s" % sess['username']);
> 
> I am printing the session id and each time the function is loaded
> I get a new session id, thus I cannot store data in the session
> to use in other functions...

class BaseSession(req[, sid, secret, timeout, lock, lockfile])
..
     save()
         This method writes session values to storage.

It doesn't appear that you are doing this. It only writes the data when 
you tell it to.

Shawn Harrison


More information about the Mod_python mailing list