CGI: Run Script then load page

Tom Bryan tbryan at python.net
Tue Aug 7 22:33:15 EDT 2001


Lang wrote:

I'm not sure whether you saw Sam's reply.  It contains some good 
suggestions, but it may lack too many details for you.  See what 
you think and post again if you run into trouble.

> The posted script, of course, works perfectly.  But looking back to my
> original posting, I realize I didn't really articulate my problem very
> clearly.

[...explanation of maintaining state across pages using hidden fields...]

> In my original updating script, it updates the values in the database,
> sets the form values as shown above, then prints out a button.  When
> this button is clicked, it loads the default month script with the
> month/year values set to those of the date I was just changing.  With
> the HTML bit quoted below I click the submit button after making
> changes, the database gets updated, and the default month script loads
> all with just one click.  That is what I want, but the values are lost
> and it defaults to the current date.  This can be a pain if I am
> making several changes in December and it's now August.

Understood.  You're familiar with the difference between GET and POST 
queries?  You might consider presenting the default page based on a 
GET query.  That way, you could redirect to a page using 
http://www.wherever.org/cgi-bin/script.py?month=04&day=25

You may also be able to write the redirect with additional data for a 
POST query, but I'm afraid that you're quickly exhausting the little 
I know about Web programming.  :-)  Perhaps someone else could 
help.

Does the cgi module transparently handle GET and POST queries so 
that the same script can be called with either?

> Sorry for the long wordy post.  I've little experience programming and
> less with Python, but I'm trying.

No problem.  Keep at it.  Again, you should look at Sam's post because 
it contains some good recommendations about using better encapsulation 
and abstraction in your program.
 
> In short, does anyone know how to submit data to a script, have the
> script run, and then load another page with the values still intact
> with no user interaction (other than the first click)?  Thanks again.

I'd seriously look at a GET query either for all of your calls to the 
script or for at least the redirect call.

Good luck,
---Tom




More information about the Python-list mailing list