[Zope] Calling Python script from ZPT

Bart Hubbard bart at barthubbard.com
Tue Sep 2 13:26:45 EDT 2003


Hello again,

I have a python script that returns an object.  I then call that script from DTML, and then call a method on that
object, like this:
  <dtml-with expr="getArticleByCategory(findCat='cancer')">
    <dtml-var view>
  </dtml-with>

I'd like to have my script call the method, and return the resulting HTML, instead, though.  My script is the following:

  import random

  zcat = context.content.Catalog
  results = zcat(category=findCat)
  itemId = random.choice(results).id
  item = context.content.HealthFeatures[itemId]
  return item;

When I try to have the script call 'view()', I get a KeyError telling me I'm referencing a non-existent object or
variable "headline" (which happens to be an attribute on that content object).  So it looks like I'm having a namespace
problem, which my DTML snippet at the top resolves.

So how do I accomplish in a single python script what I'm accomplishing above using DTML and python?

Much thanks,
bart





More information about the Zope mailing list