[Grok-dev] Re: Custom Exception Views and application_url

Martijn Faassen faassen at startifact.com
Tue Apr 1 08:40:53 EDT 2008

Lacko Roman wrote:
> Please can someone tell me how to properly use custom exception views ?

I think the main problem is that it's hard to make a custom exception 
view for IUnauthorized. I think other exception views shouldn't have the 
problem you faced.

The problem here is two-fold:

* I believe the default exception view for IUnauthorized is the one that 
causes the login-prompt to be shown. You're overriding it, so it never 

* You get your special view outside of an application, so it cannot find 
the application root.

Generally I believe that using Zope 3's authentication mechanism is 
probably preferable to overriding IUnauthorized, but I'm handwaving some 
details here. I can't think for the moment how one would customize the 
view you see if your login *failed* without overriding IUnauthorized.

Skins are indeed a possible way around this. If you make sure your 
application works in a skin and your IUnauthorized view is in a skin, 
the you cannot get it when you're not in that skin yet, i.e. the grok 
installation screen.

You can make your application be in another skin by default by doing 
something like this:

from zope.app.publication.interfaces import IBeforeTraverseEvent

@grok.subscribe(MyApp, IBeforeTraverseEvent)
def setSkin(obj, event):
    zope.publisher.browser.applySkin(event.request, MyLayer)

where MyLayer is used by the skin you want to apply, something like this 

class MyLayer(grok.IGrokLayer):

class MySkin(grok.Skin):

and you make your views be in that layer:

class MyView(grok.View):



More information about the Grok-dev mailing list