REQUEST.set question
I'm going through the code examples in the Zope Bible and I can't get the following to work: I've created a Python(Script) called 'hello' with 'name' on the parameter list and the following script body - return "Hello %s!" % name and a DTML Document with - <dtml-call "REQUEST.set('name', 'John')"> <dtml-var hello> when I view the document I get Error Type: TypeError Error Value: hello() takes exactly 1 argument (0 given) I understand that Zope should get the parameter from the REQUEST object automagically for me but it doesn't seem to do that. Is it me, or the book? Could someone shed some light on this..... FYI, I'm using a binary release of Zope 2.6.1 Thanks, Mark.
On Wed, 2003-12-03 at 04:06, Mark Ferguson wrote:
I'm going through the code examples in the Zope Bible and I can't get the following to work:
I've created a Python(Script) called 'hello' with 'name' on the parameter list and the following script body - return "Hello %s!" % name
So far so good.
and a DTML Document with - <dtml-call "REQUEST.set('name', 'John')"> <dtml-var hello>
Although scripts *can* obtain variables from REQUEST, it is not the correct way to pass arguments. Try this: <dtml-var "hello('John')"> -- or -- <dtml-call "REQUEST.set('name', hello('John'))"> <dtml-var name> HTH, Dylan
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? "Dylan Reinhardt" <zope@dylanreinhardt.com> wrote in message news:1070469388.3233.51.camel@ida.dylanreinhardt.com...
On Wed, 2003-12-03 at 04:06, Mark Ferguson wrote:
I'm going through the code examples in the Zope Bible and I can't get the following to work:
I've created a Python(Script) called 'hello' with 'name' on the parameter list and the following script body - return "Hello %s!" % name
So far so good.
and a DTML Document with - <dtml-call "REQUEST.set('name', 'John')"> <dtml-var hello>
Although scripts *can* obtain variables from REQUEST, it is not the correct way to pass arguments. Try this:
<dtml-var "hello('John')">
-- or --
<dtml-call "REQUEST.set('name', hello('John'))"> <dtml-var name>
HTH,
Dylan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Wed, 2003-12-03 at 09:11, 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
If you expect your Python Script to obtain "name" from the REQUEST, it needs to do this: return "Hello %s" % REQUEST.get('name', 'anonymous') Otherwise, pass name as an argument when you call the script: <dtml-var "hello(name)"> Either one should work fine. HTH, Dylan
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."
participants (3)
-
Dylan Reinhardt -
J. Cameron Cooper -
Mark Ferguson