[Tutor] CGI and other stuff
Tue, 14 Nov 2000 10:34:44 -0500
That may work, although I'm not using forms (at least in this part of the site).
The library reference doc for the cgi module says:
It's best to use the FieldStorage class. The other classes defined in this module are provided mostly for backward compatibility. Instantiate it exactly once, without arguments. This reads the form contents from standard input or the environment (depending on the value of various environment variables set according to the CGI standard). Since it may consume standard input, it should be instantiated only once.
but it doesn't say what those environment variables are or how they affect FieldStorage. It also mentions reading form contents, but all I want to read is a query string.
In looking through the cgi.py file to see what arguments FieldStorage might take I found the function "parse_qs(qs, keep_blank_values=0, strict_parsing=0)". Maybe this is what I want?
Do query strings need to have "name=value" format, or can I just have "value" if I only have 1 value? (ok, this is a dumb question: if I only have "value", I don't need to parse, only to get it from the environment)
On Mon, 13 Nov 2000 22:10:17 David Porter wrote:
| * D-Man <email@example.com>:
| > I'm trying to write a couple of cgi scripts to dynamically create some web
| > pages. I have finally figured out how to access the query string. Now I
| > would like some suggestions as to the best way to parse it. The parsing
| > method as well as the format of the string is completely at my discretion.
| If I understand you correctly, something like this is what you want:
| import cgi
| form = cgi.FieldStorage()
| Then you can use form as you would a dictionary with key/value pairs:
| if form.has_key("edit"):
| if form["edit"].value == "add":
| elif form["edit"].value == "delete":
| http://url/script?edit=add would then cause the function add_node() to run.
| Tutor maillist - Tutor@python.org