[mod_python] Re: form question

Byron Ellacott bje at apnic.net
Mon Nov 15 18:54:23 EST 2004


Tobiah wrote:
> The use of a session is better, but more difficult
> with mod_python.

I'd have to disagree with both of these :)

Using a session:

from mod_python import Session

sess = Session.Session(req)
# ... handle response ...
sess.save()

Pretty trivial! :)

As for the use of a session being better, that's generally not true, or 
at least, not if the session is being tracked by a cookie.  A session 
consists of all transactions performed by a user[0] with the same 
tracking ID.  If that tracking ID is in a cookie, that means /all/ 
transactions done by a user are part of the same session.

Over time, people typically become more comfortable with doing multiple 
things with their browsers at once, using tabbed browsing or multiple 
windows.  But cookies are global to all browser pages, so to a user it 
may seem like they're working two or three separate threads of 
transactions, but to the server, those threads are indistiguishable via 
cookie.

Thus, any system using cookie based sessions to track progress through 
that system will be unable to cope with multiple threads of progress; if 
that's a limitation you can live with, cookie based sessions are trivial 
to use, if it's not there are plenty of ways to work around it.

I'd strongly recommend[1] using path info to track a session:

http://www.example.com/forms/example/8vdsalk342/page1.html
http://www.example.com/forms/example/8vdsalk342/page2.html

The URL will be generated to include the session ID, and from there if 
you're using relative URLs in your markup you can ignore it.  You'll 
need to extract the session ID and pass it as the second argument to 
Session.Session(), but that's pretty trivial too[2].

-- 
bje

[0] For the pedants, read "user" as "useragent, on behalf of the user, "
[1] See http://mlm.bpa.nu/weblog/dev/web/trackingids.writeback
[2] It's marginally harder to create the session initially and get the
     SID out.


More information about the Mod_python mailing list