[mod_python] Newbie ?s regarding sessions

Jim Gallacher jpg at jgassociates.ca
Tue Nov 21 17:28:25 EST 2006


Surendra Lingareddy wrote:
> I found a few answers by experimentation.

Always the best way to learn! Push the buttons until something breaks. :)

> AuthenHandler results in a
> login pop-up and that's not what I want. 

You need to modify your apache configuration slightly. The popup is 
triggered by AuthType "Basic". Instead try something like this:

PythonDebug On
AuthType MyCookieAuth
AuthName "Private"
PythonAuthenHandler foobar
require valid-user

"MyCookieAuth" in the above configuration is arbitrary and can be just 
about anything you want. You can retrieve its value in your handler if 
you want with req.auth_type().


> I am trying to use a form to
> login. I tried session object and have been able to distinguish whether
> it is the same session or not on a reload. How can I have this session
> object be available to multiple browser pages? Should I pass it around?

Yes. The usual practice is to pass it around as an attribute of the 
request object.

req.session = Session.Session(req)

Note the use of req.session here. Using "session" as the attribute name 
will allow you to transparently use the session object with the psp 
handler. You might not plan on using psp, but it does make it easy if 
you change your mind in the future. It's not a requirement, just a 
recommended practice. The same thing goes for your request form.

req.form = FieldStorage(req)

Have fun.

Jim


More information about the Mod_python mailing list