[Zope] return structured result from Python scripts for page templates

Gabor Nagypal nagypalg@freemail.hu
Thu, 25 Jul 2002 14:06:03 +0200


Hi,

I would like to return a structured result (an "object") from a Python 
script to use it conveniently in a page template. E.g. I would like to 
have a get_person Python script which gives back a person with a name 
and an address. Then I could use a page template like:

<span tal:define="person here/get_person">
Name: <em><span tal:replace="person/name">John</span></em>, lives at
<span tal:replace="person/name">London</span>
</span>

What I tried, but did not work:

1. Create an empty object in the Python script, set some attribute, give 
back the result

class Person:
   pass
p = Person()
p.name = "Mike"
...
return p

Result:
Error Type: TypeError
Error Value: attribute-less object (assign or del)

2. Create an object with functions
class Person:
   def name(self):
     return "Mike"
...

result:
Resource not found

Sorry, the requested resource does not exist.
Check the URL and try again.

Resource: ?.Person instance at 0157E384

3. Give back a dictionary
return {'name':'Mike', 'address':'Paris'}

the script now works, but I cannot access the values from the page 
template with the person/name notation.

Any ideas how to achieve this functionality in ZOPE? I think it is so 
basic, that surely exists a way to do this.

Gabor