Hi, I have a python script(pyfoo) that expects 2 parameters foo1 and foo2. I'd like to invoke the script from a dtml code. So dtmlfoo is: ----------------------------------- <dtml-var pyfoo> ----------------------------------- my pyfoo is: ----------------------------------- ## Script (Python) "pyfoo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=foo1,foo2 ##title= ## # Example code: # Import a standard function, and get the HTML request and response objects. from Products.PythonScripts.standard import html_quote request = container.REQUEST RESPONSE = request.RESPONSE print foo1,'|',foo2,"</br>"; return printed ----------------------------------- Now, i place dtmlfoo in: /folder and place pyfoo in folder /folder/somewhere/there so i do invoke dtmlfoo: http://md5.ca/folder/somewhere/there/dtmlfoo?foo1=hello&foo2=world What I get is error, specifying that pyfoo expects 2 parameters, and i provided none. So.... i go to dtmlfoo, and change it like so: <dtml-call pyfoo> I do same invocation, it obviously works. Except that call does not expand into hello, world</br>, which is normal. How can I get <dtml-var> to behave like dtml-call, as with respect to inhereting parameters from caller to callee? I already devised a workaround, for my current problem but its ugly, using dtml-in and other things... Any help is appreciated. p. -- Create like god, rule like a king, work like a slave.
Dylan Reinhardt(zope@dylanreinhardt.com)@Mon, Mar 10, 2003 at 09:03:38AM -0800:
I have a python script(pyfoo) that expects 2 parameters foo1 and foo2. I'd like to invoke the script from a dtml code. <dtml-var "pyfoo(foo1, foo2)">
Actually what I want the python script to do is, to inherit variables from REQUEST, like it does when invoked directly from the web. If I call my python script directly, then those variables are not *inhereted* from DTML REQUEST object. I just wrote some more test cases, I guess variables that are not specified in *a* method definition, would not be imported into namespace... I guess I'd have to import all vars from REQUEST object by hand, but it seems kinda hackerish. any thoughts? p -- Create like god, rule like a king, work like a slave.
At 12:50 PM 3/10/2003, Pavel Zaitsev wrote:
Dylan Reinhardt(zope@dylanreinhardt.com)@Mon, Mar 10, 2003 at 09:03:38AM -0800:
I have a python script(pyfoo) that expects 2 parameters foo1 and foo2. I'd like to invoke the script from a dtml code. <dtml-var "pyfoo(foo1, foo2)">
Actually what I want the python script to do is, to inherit variables from REQUEST, like it does when invoked directly from the web.
Ah. In that case, you can get them like this: context.REQUEST['foo1'] when you call pyfoo as: <dtml-var pyfoo> and call dtmlfoo as: dtmlfoo?foo1=something Naturally, you'll want to do some exception handling, etc. But that's the basic technique. HTH, Dylan
Pavel Zaitsev wrote at 2003-3-10 02:09 -0800:
I have a python script(pyfoo) that expects 2 parameters foo1 and foo2. I'd like to invoke the script from a dtml code.
So dtmlfoo is:
----------------------------------- <dtml-var pyfoo>
When it expects parameters you should pass them! <dtml-var expr="pyfoo(arg1,arg2)"> The alternative (I do not recommend it!) would be to bind the DTML namespace. Dieter
participants (3)
-
Dieter Maurer -
Dylan Reinhardt -
Pavel Zaitsev