Note. To fully comply with ZCML, you must set the index variable to indicate which template you are using. So TTW tuning will work too.
# foo.py from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from zope.publisher.browser import BrowserPage class FooView(BrowserPage): index = ViewPageTemplateFile('foo.pt')
Another template that you can use with a browser view is to add an update method.
class FooView(BrowserPage): index = ViewPageTemplateFile('foo.pt') def __call__(self): self.update() return self.index() def update(self): self.portal_catalog = ...
But that is not a question.
So what is the difference? There is no difference . Browser browsing must be callable. The ZCML directive creates this so that the object has an index that should return the displayed page.
But creating a template for each call (your example) has one difference: you create a new instance of the template for each browser call. This does not apply to the class variable.
Last parameter: you do not need the class argument in the directive
<configure xmlns:browser="http://namespaces.zope.org/browser"> <browser:page … template="foo.pt" … /> </configure>
For more information, you should read the directive code that uses SimpleViewClass, where src is the name of the template .
source share