[Zope] Calling Python script from ZPT

Peter Sabaini peter at sabaini.at
Tue Sep 2 20:05:41 EDT 2003


see the zope book, advanced scripting chapter

http://zope.org/Documentation/Books/ZopeBook/2_6Edition/ScriptingZope.stx

search for "Calling DTML from Scripts"


Bart Hubbard wrote:
> 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
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3461 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.zope.org/pipermail/zope/attachments/20030902/3bf1cb90/smime.bin


More information about the Zope mailing list