[PEAK] Problem with ZopePageTemplates

Phillip J. Eby pje at telecommunity.com
Sun Dec 21 17:44:31 EST 2003


At 12:54 PM 12/7/03 +0000, William Trenker wrote:
>First, being new here, I'm not sure if I should ask for help on examples 
>from the Wiki on this mailing list, or if I should add a comment to the 
>relevant Wiki page.  If I shouldn't be addressing this question here let 
>me know and please accept my apologies.)

The mailing list is fine.  I expected Ulrich would answer this one (as it's 
his demo), so I skipped over it.


>I've been exploring Zope X3 (Milestone 4) on my Linux system so when I saw 
>the ZopePageTemplates page on the DevCenter Wiki I thought I'd give it a 
>try.  Unfortunately I'm getting a lengthy traceback (gory details at the 
>end of this post) which boils down to "NameError: name 'IWebMethod' is not 
>defined".

That's because Ulrich's demo for this was thrown together at a very early 
stage of peak.web development, and a number of things have 
changed.  IWebMethod is now IWebPage, for one, and the 'render' method of 
'PageTemplateAsWebMethod' should take a 'context' argument instead of 
'interaction', and to get the interaction it should use 
'context.interaction'.  It also probably should *not* be encoding the 
output as UTF-8, but instead leave that to the response object.  The 
'AnonInteraction' class is unnecessary, and this statement:

     interactionClass = binding.Constant(
         AnonInteraction, offerAs=[web.INTERACTION_CLASS]
         )

should be removed.  There may be other problems as well, but these are the 
ones that are obvious to me from a reading of zpttest.py.

Ulrich, can you update your example with these fixes?  Perhaps it would 
also be appropriate to add a resource loader for ZPT's, by subclassing 
web.TemplateResource like this:

class ZPTResource(web.TemplateResource):
     theTemplate = binding.Make(lambda self: PageTemplateFile(self.filename))


Then, you can add this to a 'resources.ini' file in the same directory:

[Files *.zpt]
file_factory = "zpttest.ZPTResource"

This should then allow .zpt files to be referenced using e.g.:

class ZPTTestApp(binding.Component):

     security.allow(
         index_html = [security.Anybody]
     )

     index_html = web.bindResource('index')

Note that resource lookups are polymorphic; that is, they don't need an 
extension as long as there's only one resource with the given base 
name.  This means that if someone who's customizing your app wants to use a 
different kind of template file, they don't have to change your code.

(Hmm.  I wonder if I should get rid of 'bindResource' and replace it with a 
'ResourceFor' class, so that it's 
'binding.Obtain(web.ResourceFor("index"))', or something like that.  We're 
trying to get away from 'bindSomething' verbs in favor of nouns passed to 
Obtain or Make, where possible.)




More information about the PEAK mailing list