[mod_python] query_vars and form_vars

Daniel J. Popowich dpopowich at comcast.net
Tue Jul 6 10:45:35 EDT 2004


mod_python user writes:
> I'm new to python and consequently mod_python but have discovered the 
> servlet" package, and actually have a small templated webapp up and 
> running.  Extremely powerful language.
> 
> 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?

Since you're acquiring this data from a POST you will probably want to
use form_vars instead of query_vars and set it like this:

   form_vars = [('name', [])]

Setting form_vars this way tells the servlet handler to get the value
of 'name' from the FieldStorage instance with the getlist method.

Setting form_vars like this:

   form_vars = ['name']

tells the handler to retrieve 'name' using the getfirst method.

Check out lesson #10 in the tutorial that comes with Mod_python
Servlets for a discussion concerning retrieving lists.  Lesson #12
discusses query_vars vs. form_vars.

Daniel



More information about the Mod_python mailing list