[Zope3-Users] view vs page confused

Dominique Lederer dominique.lederer at inode.at
Tue Mar 27 12:03:54 EDT 2007


Marius Gedminas schrieb:
> On Wed, Jan 24, 2007 at 08:31:52PM +0100, Dominique Lederer wrote:
>> can someone explain me please when to use browser:view and when browser:page?
> 
> As far as I understand, the intended use of <browser:page> is to define
> views that are accessible to browsers by using URLs.
> 
> The intended use of <browser:view> is to define helper views that are
> accessible to page templates in TALES expressions like
> tal:attributes="href context/@@absolute_url".
> 
> I might be wrong.
> 
>> and when would i inherit a View Class from zope.publisher.BrowserView
>> and when from zope.publisher.BrowserPage, and why do i need them when
>> i could just inherit from object without any errors?
> 
> A browser page must implement IBrowserPublisher if you want it to be
> accessible from the outside.  BrowserPage does that.  The <browser:page>
> also does that, but in a different way.  The directive does deep magic
> -- it constructs a new class on the fly that implements
> IBrowserPublisher and inherits from the view class you've specified.  It
> can also provide a 'index' attribute and a default implementation of
> __call__.
> 
> BrowserView only gives you a useful __init__.  If you inherit directly
> from object, you'll have to define __init__ by yourself.
> 
> Looking at the code I see that BrowserView also gives you a __parent__
> property that is used by the standard Zope 3 security policy.  I do not
> think it is all that important, as usually views in Zope3-land are not
> security proxied.
> 
> Magic is going out of fashion in Zope3-land.  In my personal opinion
> the best practice for Zope 3 views is to follow this pattern:
> 
>     class MyView(BrowserPage):
>         adapts(ISomeContext, IBrowserRequest)
> 
>         template = ViewPageTemplateFile('...')
> 
>         def __call__(self):
>             # do form processing, if any
>             return self.template()
> 
> and then register it with <browser:page>.
> 

so if i create a class which inherits from BrowserView, and then register it via
zcml as browser:page, it becomes adaptes to IBrowserRequest an turns to a
BrowserPage (via the on-the-fly created class)? so inheriting from BrowserPage
instead from BrowserView would make no sense with my example?

cheers
Dominique


More information about the Zope3-users mailing list