Way to distinguish between POST and GET data in Python CGIs?
poiboy
bitbucket at safe-mail.net
Thu Aug 28 05:32:38 EDT 2003
Hi Simon,
Regarding mod_python:
* Check req.method in ('GET', 'POST').
* GET variable strings are accessible via
req.args,
req.parsed_uri[apache.URI_QUERY], or
req.subprocess_env['QUERY_STRING'] after calling req.add_common_vars().
* POST variable strings are in the client's request body, accessible via
req.read()
* The variable list strings can be parsed using functions in the cgi
and urllib modules.
Viewing mod_python as an Apache interface which accomodates
web-scripting instead of (just) a web-scripting tool helps
considerably. Think "light on the context, heavy on the construct."
Example:
4.5.3: "The request object is a Python mapping to the Apache
request_rec structure. When a handler is invoked, it is always
passed a single argument - the request object."
See http://httpd.apache.org/dev/apidoc/apidoc_request_rec.html for the
structure's nitty grit.
Wearing my Clueless CGI Apologist cap, I believe that it is the
server's duty to set environment variables (like REQUEST_METHOD) and
call an appropriate script with a query string (close enough). In
other words, the script's only *required input* is the query string
itself. Since environment (or "meta") variable accessibility is
"system defined," a frugal cgi module was a safe bet. Just guessing.
Aloha,
the poiboy
More information about the Python-list
mailing list