[ZPT] Problems using PageTempateFile from a disk product

Evan Simpson evan@zope.com
Wed, 06 Feb 2002 11:48:08 -0500


Kevin Gill wrote:
 > If I create the PageTemplateFile object during the initialisation of
 > the class, I get an exception when I restart Zope and view the page
 > again.
 >
 > def __init__(self, id, title=None):
 >   self.View1 = PageTemplateFile('html/viewMyClass', globals())

As you discovered, this will not work.  PageTemplateFiles are not meant
to be attached to instances.  They should only be defined in the body of 
your class, like this:

class AClass:
     View1 = PageTemplateFile('html/viewMyClass', globals())

Cheers,

Evan @ Zope