[Tutor] CGI and other stuff

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Tue, 14 Nov 2000 08:26:45 -0800 (PST)


On Tue, 14 Nov 2000, D-Man wrote:

> 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.

Forms create URLS with query strings embedded into them.  If you manually
enter the query strings, you should still be able to use FieldStorage to
get at them.


> 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?

If you didn't want to use FieldStorage, then you could use parse_qs on
os.environ['QUERY_STRING'].  CGI's set up your inputs within environmental
variables; try writing a CGI that prints out os.environ, and you'll see
a LOT of variables.


> 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)

From what I remember, they have to be in name/value pairs.  Since there's
a module that automatically parses the query string, you should use it; it
isn't too hard to use.

I hope this helps!