Session CGI!
Harry George
harry.g.george at boeing.com
Tue Feb 24 06:04:50 EST 2004
Erno Kuusela <erno-news at erno.iki.fi> writes:
> johng2001 at rediffmail.com (John) writes:
>
> > > You could use cookies and/or database writes.
> >
> > Sadly that is what I want to avoid :-(
>
> see here: http://www.catdancers.com/webmags/webtech/1998/03/perl/
>
> it's about perl, but you can apply the idea to python too.
>
> -- erno
There are two problems:
1. Where to store state. Databases, cookies, and pickle files are
available. I've used pickle files for low volume apps.
2. How to structure the CGI code. Of course, something like webware
or twisted would hide it all, but let's assume you are writing from
scratch. Since this is a stateless protocol, we can borrow from
another (and solved) stateless protocol -- sockets.
So for each webpage,we make 2 functions (or methods): send_xyz and
recv_xyz. On wakeup,we check a hidden field to determine which
"xyz" is arriving, and call its recv. There we use another hidden
field (or an SSL tag) to get the right database or pickle data and
load it into an object. Continue processing as if there was no
time gap. At end (ready for more user input), call the proper
"send". It prepares the hidden fields, saves the state, and prints
the outgoing page. The script exits and we are back at the
browser.
--
harry.g.george at boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007
More information about the Python-list
mailing list