Deformed Form

Stephen Hansen me+list/python at ixokai.io
Thu Jun 10 14:07:18 EDT 2010


On 6/10/10 10:48 AM, Victor Subervi wrote:
> Now, create_edit_passengers3() is called by the form/submit button in (you
> guessed it) create_edit_passengers2.py, the latter containing a var in it
> which *should* be accessible to create_edit_passengers3.py, one would think.

Wait, wait, wait.

If a user is browsing to, say,
http://example.com/create_edit_passengers2.py; that script will be run,
and once -done-, print out a form which the user sees.

At that point, create_edit_passengers2.py is dead. Gone. Over.

Once a person then clicks Submit, and the form is sent to
http://example.com/create_edit_passengers3.py; its a whole new
environment (assuming you're using CGI, which it appears you are).

The *only* way for state or data to get from one script to another is
not importing, or shared variables, or anything like that: you *have* to
pass it into that form, and extract it from the resulting form. You can
pass the actual variables as a <input type="hidden">, and then extract
it like any of the user-fields. Or, you can write out your state to a
local file with some unique ID, and just write out into the form that
unique ID. Or use a cookie session. Etc.

You *can't* pass variables around script-to-script among separate CGI
sessions. It just totally doesn't work like that. Any success you think
you have had is false; it works by mere accident or illusion. Each CGI
script stands alone. It starts, runs, executes, then closes. No state is
preserved unless you *explicitly* preserve it.


*However*, if I put that *same_line* of code
> in New_Passengers.py (and fn of same name). it will give me the correct
> value, which I can then pass back to the calling script
> (create_edit_passengers3.py). 

There is no passing going on. You're just tricking yourself into
thinking you're passing. The only way to pass variables between CGI
scripts is to explicitly write them out to the form, and read them in
from the form. You can't pass them around pythonically.

-- 

   Stephen Hansen
   ... me+list/python (AT) ixokai (DOT) io

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 553 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20100610/afde7824/attachment-0001.sig>


More information about the Python-list mailing list