[Grok-dev] Custom Exception Views and application_url

Sebastian Ware sebastian at urbantalk.se
Mon Mar 31 11:13:37 EDT 2008


I might have had the same problem. What happened was that I had  
written an application for a customer. After a while I added the  
exception view to the running application. It never worked eventhough  
everybody said the code should be ok.

Later I used exactly the same code but created a new application  
(which wasn't an option in the first case due to the issue of  
migrating customer data). Suddenly it worked!

So try the same code on a new application and see if that helps. If it  
does, maybe someone can explain how to add an exception view to an  
existing application.

Mvh Sebastian

31 mar 2008 kl. 14.32 skrev Lacko Roman:
> Hi,
>
> First of all, thank you Grok and ZOPE developers for a wonderfull  
> web framework.
>
> I am finishing my first web project with Grok.
> But i have one problem with customized exception views.
> I created a custom view “Unauthorized” for exception “IUnauthorized”:
>
> class Unauthorized(grok.View):
>     grok.context(IUnauthorized)
>     grok.name('index.html')
>
>     def update(self):
>>
> For that view I created template, in that template I use something  
> like that (please note “${view/application_url}”):
>
>   <a i18n:translate="" tal:attributes="href string:${view/ 
> application_url}/offers?offertype=sale&realtytype=apartment">sale</a>
>
> When I try to browse grok administrator at url http://localhost:8080  
> to create application instance, the following page is rendered in  
> browser:
>
> >>>
> <class 'zope.security.interfaces.Unauthorized'>
> A server error occurred.
>
> <<<
>
> And following exception is thrown, (copy-paste from console output):
>
> >>>
>   2008-03-31T14:11:39 ERROR SiteError Exception while rendering view  
> on exception
>   ...
>   <FILES IN STACK TRACE>
>   ...
>   File "d:\src\klucsiteenv\klucsite\buildout-eggs\zope.tales-3.4.0a1- 
> py2.5.egg\zope\tales\tales.py", line 696, in evaluate
>     return expression(self)
>    - d:\src\klucsiteenv\klucsite\src\klucsite\app_templates 
> \unauthorized.pt
>    - Line 20, Column 6
>    - Expression: <StringExpr u'${view/application_url}/offers? 
> offertype=sale&realtytype=apartment'>
>    - Names:
>       {'args': (),
>        'context': <zope.app.folder.folder.Folder object at  
> 0x0208C2F0>,
>        'default': <object object at 0x00A705E8>,
>        'loop': {},
>        'nothing': None,
>        'options': {},
>        'repeat': {},
>        'request': <zc.resourcelibrary.publication.Request instance  
> URL=http://localhost:8080/favicon.ico>,
>        'static': <grok.components.DirectoryResource object at  
> 0x02F8D4B0>,
>        'template': <grok.components.TrustedFilePageTemplate object  
> at 0x02E7D310>,
>        'view': <klucsite.app.NotFound object at 0x02F8D3F0>}
>   File "d:\src\klucsiteenv\klucsite\buildout-eggs\zope.tales-3.4.0a1- 
> py2.5.egg\zope\tales\expressions.py", line 261, in __call__
>     v = var(econtext)
>   File "d:\src\klucsiteenv\klucsite\buildout-eggs\zope.tales-3.4.0a1- 
> py2.5.egg\zope\tales\expressions.py", line 217, in __call__
>     return self._eval(econtext)
>   File "d:\src\klucsiteenv\klucsite\buildout-eggs\zope.tales-3.4.0a1- 
> py2.5.egg\zope\tales\expressions.py", line 211, in _eval
>     return ob()
>   File "d:\src\klucsiteenv\klucsite\buildout-eggs\grok-0.11.1- 
> py2.5.egg\grok\components.py", line 186, in application_url
>     raise ValueError("No application found.")
> ValueError: No application found.
> <<<
>
> As I understand, the exception of type “IUnauthorized” is thrown.  
> Then my custom view for that exception is evaluated and failed on  
> path expression: ${view/application_url}/offers? 
> offertype=sale&realtytype=apartment. I discovered that exception  
> with value “ValueError: No application found.” is rased in function  
> application_url(). I understand that there is no application  
> created, but I can not create one, if I can not login to Grok  
> administrator. I understand that this is because my custom exception  
> view somehow replaced default view that popups login form.
>
> Please can someone tell me how to properly use custom exception  
> views ?
>
> Thank in advance for any help,
> Roman Lacko
>
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list