[Zope] using ZPT to invoke an External Method and pass in var
Tim Lynch
lynch@gould.mannlib.cornell.edu
Fri, 04 Oct 2002 7:52:44 EDT
That did it!
Thanks Chris
>Try:
> <span tal:define="stateNumber python:33">
> The <span tal:replace="python:here.getStateName(stateNumber)" />
> </span>
>
>And then comment the zopelab recipe.
>
>>-----Original Message-----
>>From: Tim Lynch [mailto:lynch@gould.mannlib.cornell.edu]
>>Sent: Friday, 4 October 2002 3:07 p.m.
>>To: zope@zope.org
>>Subject: [Zope] using ZPT to invoke an External Method and pass in
>>variables
>>
>>
>>
>>I've been trying to get a page template to call an external method, passing
>>some
>>variables in the call. I've been trying to follow an example I found on
>>ZopeLabs:
>>(http://www.zopelabs.com/cookbook/1008969252):
>>
>>
>> Submitted by: runyaga
>> Last Edited: 2002-02-18
>> Category: Python(External Method)
>>
>> ---------------------------------------------------------------------
>> Description:
>> if you want to use any python libraries, or xmlrpclib you can do this
>> from python external methods. this is very simple.
>> ---------------------------------------------------------------------
>>
>> Source (Text):
>> #inside $ZOPE/Extensions
>> #create a file, xmlrpc_example.py
>> from xmlrpclib import Server
>>
>>
>> def getStateNameByNumber(number=1):
>> """ python lib example """
>> # simple test program (from the XML-RPC specification)
>> # server = Server("http://localhost:8000") # local server
>> server = Server("http://betty.userland.com")
>> try:
>> return server.examples.getStateName(number)
>> except Error, v:
>> raise v
>>
>> #inside ZOPE create a External Method:
>> #id: getStateName
>> #module: xmlrpc_example
>> #function: getStateNameByNumber
>>
>> #then you can test that or call it from a Pagetemplate:
>> <span tal:define="stateNumber python:33">
>> The #<span tal:replace="stateNumber"/> is
>> <span tal:replace="python:getStateName(stateNumber)" />
>> </span>
>>
>>
>>When I follow this as given, I get:
>>
>>Error Type: NameError
>>Error Value: global name 'getStateName' is not defined
>>
>>
>>
>>If I revise the ext. method call to:
>> <span tal:replace="here/getStateName" />
>>
>>the call succeeds (using the default value) but I can't figure
>>out how to pass in a value. Anything I try that has a variable
>>in parentheses following the function name fails.
>>
>>The external method is OK as I've tested it outside of zope.
>>(actually, the ext. method is not actually making an xml-rpc call
>>at all -- I'm just returning whatever number is passed in as a sring)
>>
>>I've pored over the mail list archives, checked zopelabs for other
>>examples, to no avail.
>>
>>
>>I'm running Zope 2.60b1 if that makes any difference.
>>
>>
>>- Tim Lynch
>> tlynch@nal.usda.gov