saving state in Python/CGI

Dave Cole djc at object-craft.com.au
Fri Sep 20 22:35:49 EDT 2002


>>>>> "Tim" == Tim Churches <tchur at optushome.com.au> writes:

Tim> 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?

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

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

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

I am one of the authors Tim is referring to.  The application you have
described has very similar data capture and processing requirements to
Tim's application.  Albatross was developed specifically with that
type of problem in mind.

If you have the time you should try a few of the toolkits to see which
most suits the way you like to solve problems.  One of the big features
that Albatross has going for it is the ability to expose deeply nested
recursive data structures to HTML form input.

Read point 3 of the following page for a description of the alias feature:

  http://object-craft.com.au/projects/albatross/albatross/tag-input-alias.html

- Dave

-- 
http://www.object-craft.com.au



More information about the Python-list mailing list