Python CGI

Tim Roberts timr at probo.com
Thu Dec 1 03:08:41 EST 2005


"jbrewer" <jeremy.d.brewer at gmail.com> wrote:
>
>I need to update a CGI script I have been working on to perform
>validation of input files.  The basic idea is this:
>
>1.) HTML page is served
>2.) User posts file and some other info
>3.) Check file for necessary data
>    * If data is missing, then post a 2nd page requesting needed data
>    * If data is present, continue to 4
>4.) Process input file and display results (processing path depends on
>whether data from 3 was present in file or had to be input by user)
>
>I'm unsure of the best way to implement step 3.  Is it even possible to
>put all of this into one script?  Or should I have one script check the
>file for the data, then pass the info on to a 2nd script?  The
>cgi.FieldStorage() function should only be called once, so it seems
>like it's not possible to read a form and then repost another one and
>read it.  If this is true and I need 2 scripts, how do I pass on the
>information in step 3 automatically if the file has the proper data and
>no user input is needed?

Each web transaction standsalone.  User sends request, you send reply, your
CGI process ends.  Every new request is another run.

So, you can either use one script per operation, or you can use one script
and detect which step it is using, for example a hidden field.

If you need common file processing in both scripts, I'm sure you already
know you can put that code in a separate Python file and import it into the
two CGI scripts.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list