[Zope] Pass Variable to ZSQL from HTML page REQUEST object.

J Cameron Cooper jccooper at jcameroncooper.com
Tue Feb 3 18:51:30 EST 2004

RI Dunfey wrote:

>I have a html page with the following dtml tag:
><dtml-in get_names>
><dtml-var NAME></a>
>When the page loads it calls the zsql that returns NAME and JOB.  So I can 
>access these from the request object, as above.
>However, how would I pass a variable to the zSQL?  The value of the variable I 
>want to pass is stored in the request object when the page loads.  I have 
>looked in the book but this is not explained?  In the example above, I would 
>wish to pass a vaiable to the get_names SQL?
ZSQL methods render their query with DTML, and I think you can just 
treat them as such. Meaning that you can just use that request parameter 
in the ZSQL method just as you would in a DTML method you called.

A more general answer (and what you need to do if I'm wrong above -- I 
haven't done that in a long time) is that you call it like any Python 
method. Give the ZSQL method some parameters through the ZMI and then 
call it like such::

some_method(apples=varapples, bananas=varbananas, oranges=0)

Note that positional parameters will not work. You must use keyword 
parameters as above. In DTML you use the 'expr=""' or simply the quoted 
syntax to do python. In ZPT, you use the 'python:' statement. In Python 
scripts or filesystem code, well, you have no alternative syntax.


"Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design."

More information about the Zope mailing list