[mod_python] query_vars and form_vars

Gustavo Córdova Avila gustavo.cordova at q-voz.com
Fri Jul 9 19:49:14 EDT 2004

Don't get y'alls panties in a bunch, QUERY_STRING parameters and POSTed 
data are ORTHOGONAL, they don't have anything to do with each other.

I normally parse urlencoded parameters using something like:

    >>> params = dict(util.parse_qsl(request.args or ""))

because normally I only expect a single instance of any parameter, and 
any extra instances will get clobbered by this (not that this particular 
application cares, validation and verification happens after parsing).

IF you know for a fact that the POSTed data is URLEncoded, you can do 
something like the previous snippet and build a dictionary of those 
parameters also:

    >>> data = req.read(req.content_length)
    >>> posted_params = dict(util.parse_qsl(data or ""))

So now you have two dictionaries.

Parsing for multiple instances of a single parameter is left as an 
excersize to the reader.



Jorey Bump wrote:

> Jorey Bump wrote:
>> mod_python user wrote:
>>> I would like to be able to retrieve both _form_ and _query_ 
>>> variables, even if they share the same name. e.g.
>>> <form method='post' action='/?name=NAME_ONE'> <input type='hidden' 
>>> name='name' value='NAME_TWO' /> <input type='submit' /> </form>
>>> It seems that when both a GET and POST variable share the same name
>>>  that the GET (query) variable always wins.
>>> Does anybody know how this might be accomplished?
>> I don't know about servlets, but mod_publisher returns a list:
> Duh. I mean mod_python.publisher. :P
>> I don't know what causes this behaviour. Since only a POST request is
>> sent, not a GET, I would expect any arguments in the URL to be 
>> ignored and only variables in the message body to be recognized.
> FWIW, mod_php ignores the URL arguments:
>  Array ( [name] => NAME_TWO )
> This seems more appropriate. A user shouldn't be allowed to mess with 
> POST data so easily.
> If this gets fixed (assuming it's a bug), you can still use 
> req.unparsed_uri and do your own parsing. For example, use publisher 
> and create foo.py with this function:
>  def test(req):
>      return req.unparsed_uri
> Then view the results at:
>  http://localhost/foo.py/test?name=something
> Extract whatever you want from the resulting string.
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gustavo.cordova.vcf
Type: text/x-vcard
Size: 449 bytes
Desc: not available
Url : http://modpython.org/pipermail/mod_python/attachments/20040709/dc6f9f98/gustavo.cordova.vcf

More information about the Mod_python mailing list