[Zope3-Users] redirect to views dynamically

FB fbo2 at gmx.net
Tue Feb 6 15:29:46 EST 2007


On Tue, Feb 06, 2007 at 09:01:06PM +0100, Dennis Schulz wrote:
> Hello List,
> 
> one question about views:
> 
> I know that is is possible to register a default view for an object.
> Is there a way to decide, at runtime, which view to call?
> 
> Maybe a traversal adapter can do this,but is there an easier way?

You don't even need a redirect for that:


 from zope.app import zapi
 from zope.publisher.browser import BrowserView

 class DecisionView(BrowserView):
    def __call__(self):
       if ...:
          viewname='index.html'
       else:
          viewname='something_else.html'
       return zapi.getMultiadapter((self.context,self.request),name=viewname)()


Regards,

Frank


More information about the Zope3-users mailing list