[Zope] useing the REQUEST variable in python scripts

Tino Wildenhain tino at wildenhain.de
Tue Sep 28 02:12:36 EDT 2004


Hi,

Am Di, den 28.09.2004 schrieb Tim Zegir um 6:39:
> Hi All,
> 
> I'm trying to get some form variables in a python script.
> The form variables are dynamic (grabbed from a database).
> I want to use a variable in the script (something like REQUEST[myvar]) to
> get the input values.
> But when I use that code I get a key error.
> 
> Does anyone know how to get a variable from a form with code like that?

So you have a form with different element names each time?
You access REQUEST via context.REQUEST
if you dont know if REQUEST or its sub element form
has a given key, you can use the standard python
mapping interface (see documentation for dictionary)

This for example has:
context.REQUEST.form.has_key("nameofyourvar")

which returns True if this variable has been sent

context.REQUEST.form.get("nameofyourvar",defaultvalue)

which would return the value of the form element
if sent or the defaultvalue otherwise.


HTH
Tino.



More information about the Zope mailing list