[Zope] Re: REQUEST.set question
J. Cameron Cooper
jccooper at jcameroncooper.com
Wed Dec 3 21:22:19 EST 2003
Mark Ferguson wrote:
>The whole point of my question was about getting parameters from the REQUEST
>object into Python scripts, so perhaps if I restate the example -
>
>I've got a DTML Document called hDoc:
> <form action="./hDoc" method="POST">
> Name: <input type="text" name="name" value="">
> <input type="submit" value="Submit">
> </form>
> <dtml-if "REQUEST.get('REQUEST_METHOD') == 'POST'">
> <dtml-var hello>
> </dtml-if>
>
>and a Python script -
> return "Hello %s!" % name
>
>According to the Zope Bible book this should work, but it doesn't. If I mod
>the DTML to -
>
><form action="./hDoc" method="POST">
> Name: <input type="text" name="name" value="">
> <input type="submit" value="Submit">
></form>
><dtml-if "REQUEST.get('REQUEST_METHOD') == 'POST'">
> <dtml-var "hello(REQUEST.get('name'))">
></dtml-if>
>
>It works as expected. So the question is, I am doing something wrong or is
>the book wrong?
>
>
The PythonScript
automagically-turn-request-parameters-into-script-parameters feature
only works when you directly request a Python script. But if you make
your script this it will work::
return "Hello %s" % context.REQUEST.name
It shares the same REQUEST object, as you expected. Notice that the
script, besides accepting parameters, can also get the acquisition
context and the DTML namespace (if called from DTML), so there's usually
no need to use the REQUEST as a way to pass data around.
--jcc
--
"My point and period will be throughly wrought,
Or well or ill, as this day's battle's fought."
More information about the Zope
mailing list