Python CGI

J

jbrewer

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?

Sorry if this is a dumb question (or unclear), but this is my
(ever-growing) first CGI script. Thanks.
Jeremy
 
T

Tim Roberts

jbrewer said:
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.
 
F

Fuzzyman

That doesn't sound too difficult to do in a single script.

As Tim has mentioned, you can always separate the code in two modules
and just import the one needed for the action being performed.

Your script just needs to output different HTML depending on the result
- with a different form depending on what information is required.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
 
J

jbrewer

Thanks guys. I didn't realize that hidden form fields were so easy to
use.

Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top