saving state in Python/CGI

Tim Churches tchur at optushome.com.au
Fri Sep 20 17:57:57 EDT 2002


Frank Gibbons wrote:
> 
> Hi,
> 
> I've been using Python (and Jython) for about 5 months now. So far, so
> great. I'm building a CGI app that has about 5 different stages, and I need
> to maintain state between them. Specifically, it's a scientific tool that
> requires the user to upload a (possibly quite large) datafile, processes
> it, does some computation, then hands it back (formatted) with results.
> 
> I need access to the data on each page, yet don't want to pass it as a
> hidden field, because of its potential size. In Perl, I could just use the
> save() method from CGI.pm to save the form on the server side, pass a
> session key in a hidden field, then retrieve the data using the key. For
> the life of me, I can't find an equivalent way in Python. cgiFormStorage
> looks like a dictionary, but it's immutable, so you can't retrieve data
> from disk and add it to the form. cgi.py appears to have no analog to
> CGI.pm's save() method, at least not that I've been able to find. I've
> tried pickling the form, but that doesn't work either (it saves something
> to disk alright, but not the large data retrieved from a multi-part form
> file upload).
> 
> Perhaps I've missed something. Maybe that's just not how you do things in
> Python. Can anyone help?

You need to use one of the (many) Python Web app frameworks which help
(to greater
or lesser degrees) with storing state and other typical Web app tasks.
There is a 
list of such frameworks available at
http://www.python.org/cgi-bin/moinmoin/WebProgramming

Of these, I have only used Albatross, but I can heartily recommend it -
it was specifically
designed with highly stateful applications in mind, is elegantly
designed and well written and
has excellent documentation and the authors are very helpful. We use it
for a range of
quite complex epidemiological applications.

However, many of the other frameworks list on the above site are also
reputed to be very good and
you should consider all of them before making a choice.

Tim C

> 
> Thanks,
> 
> -Frank Gibbons
> 
> PhD, Computational Biologist,
> Harvard Medical School BCMP/SGM-322, 250 Longwood Ave, Boston MA 02115, USA.
> Tel: 617-432-3555       Fax:
> 617-432-3557       http://llama.med.harvard.edu/~fgibbons
> 
> --
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list