[mod_python] publisher form values

Graham Dumpleton grahamd at dscpl.com.au
Wed Jan 11 16:42:00 EST 2006


Dave Britton wrote ..
> I am running modpython 2.7 on apache 1.3
> I have an html form that is generated dynamically based on database entries,
> so it may have an arbitrary number of fields displayed. In the module that
> generates them they are numbered field1, field2, etc.
> eg: (dynamically output html)
> 
> <form action = "handleform" method = "post">
> Field1 <input type = "text" name = "field1"><br>
> Field2 <input type = "text" name = "field2"><br>
> Field3 <input type = "text" name = "field3"><br>
> <input type = "submit"></form>
> 
> -- now, there might be 1 or 2 or x number of input fields, so I want to
> use
> the **kwds parameter form for the processing function, eg:
> 
> def handleform(req, **kwds):
> 
> and I was hoping this would just work, and I would get a nifty and
> arbitarily long set of variables name field1 - fieldn, but I couldn't seem
> to make the syntax work. I reverted to just using this:
> 
> cgi={}
>  for i in req.form.list:
>       cgi[i.name]=i.value
> 
> to construct my own dictionary, but I am wondering if there is supposed
> to
> be an easy way to do this in publisher and I am just too unfamiliar with
> using **kwds to figure it out.

In mod_python 2.7, having unspecified form arguments passed through
a keyword argument dictionary, ie., '**kwargs' syntax, was not supported.
This feature is in mod_python 3.1 though.

Your options are to access req.form as you are doing, don't use numbers
on form arguments in list as suggested by other poster, or upgrade to
Apache 2.0/mod_python 3.1.4.

The only other option that exists is to use mod_python.publisher drop in
replacement from Vampire. This supports '**kwargs' syntax for unspecified
form parameters. The Vampire version of publisher is the only way of
currently getting a system which will work the same on mod_python 2.7
and mod_python 3.1.

Graham


More information about the Mod_python mailing list