[Grok-dev] Custom not found page

Svenn Helge Grindhaug Svenn.Helge.Grindhaug at bccs.uib.no
Fri Nov 13 17:21:57 EST 2009


Hi,

I'm having problem customizing the  not found error page (404).
I have registered a view for the INotFound interface:

import grok
from zope.publisher.interfaces import INotFound


class MblosumNotFound(grok.View):
    grok.context(INotFound)
    grok.name('index.html')

    def update(self):
        self.request.response.setStatus(404)

    def render(self):
        return 'Page not found'

This works. But when I try to replace the render method with a template using 
my own macro page it fails to render:

class MblosumNotFound(grok.View):
    grok.context(INotFound)
    grok.template('mblosumnotfound')
    grok.name('index.html')

    def update(self):
        self.request.response.setStatus(404)

The template (mblosumnotfound.pt) looks like this:

<html metal:use-macro="context/@@mblosum/macros/standard">
	<metal:block fill-slot="content">
  		<h2>Page not found.</h2>
  	</metal:block>
</html>

What am I missing here?  Any hints appreciated.

The traceback:

2009-11-13 19:29:51,123 ERROR [SiteError] Exception while rendering view on 
exception                                                                           
Traceback (most recent call last):                                              
  File "/home/svenn/.buildout/eggs/zope.app.publication-3.4.3-
py2.5.egg/zope/app/publication/zopepublication.py", line 334, in 
handleException                  
    body = mapply(view, (), request)                                            
  File "/home/svenn/.buildout/eggs/zope.publisher-3.4.6-
py2.5.egg/zope/publisher/publish.py", line 108, in mapply                                               
    return debug_call(obj, args)                                                
  File "/home/svenn/.buildout/eggs/zope.publisher-3.4.6-
py2.5.egg/zope/publisher/publish.py", line 114, in debug_call                                           
    return obj(*args)                                                           
  File "/home/svenn/.buildout/eggs/grokcore.view-1.7-
py2.5.egg/grokcore/view/components.py", line 63, in __call__                                               
    return self._render_template()                                              
  File "/home/svenn/.buildout/eggs/grokcore.view-1.7-
py2.5.egg/grokcore/view/components.py", line 67, in _render_template                                       
    return self.template.render(self)                                           
  File "/home/svenn/.buildout/eggs/grokcore.view-1.7-
py2.5.egg/grokcore/view/components.py", line 228, in render                                                
    return template.pt_render(namespace)                                        
  File "/home/svenn/.buildout/eggs/zope.pagetemplate-3.4.0-
py2.5.egg/zope/pagetemplate/pagetemplate.py", line 115, in pt_render                                 
    strictinsert=0, sourceAnnotations=sourceAnnotations)()                      
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 271, in __call__                                                  
    self.interpret(self.program)                                                
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 346, in interpret                                                 
    handlers[opcode](self, args)                                                
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 891, in do_useMacro                                               
    self.interpret(macro)                                                       
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 346, in interpret                                                 
    handlers[opcode](self, args)                                                
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 536, in do_optTag_tal                                             
    self.do_optTag(stuff)                                                       
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 521, in do_optTag                                                 
    return self.no_tag(start, program)
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 516, in no_tag
    self.interpret(program)
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 346, in interpret
    handlers[opcode](self, args)
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 408, in do_startTag
    rendered = attrAction(self, item)
  File "/home/svenn/.buildout/eggs/zope.tal-3.4.1-
py2.5.egg/zope/tal/talinterpreter.py", line 485, in attrAction_tal
    evalue = self.engine.evaluateText(item[3])
  File "/home/svenn/.buildout/eggs/zope.tales-3.4.0-
py2.5.egg/zope/tales/tales.py", line 704, in evaluateText
    text = self.evaluate(expr)
  File "/home/svenn/.buildout/eggs/zope.tales-3.4.0-
py2.5.egg/zope/tales/tales.py", line 696, in evaluate
    return expression(self)
  File "/home/svenn/.buildout/eggs/zope.tales-3.4.0-
py2.5.egg/zope/tales/pythonexpr.py", line 59, in __call__
    return eval(self._code, vars)
  File "<string>", line 1, in <module>
  File "/home/svenn/.buildout/eggs/grok-1.0a4-py2.5.egg/grok/components.py", 
line 297, in application_url
    raise ValueError("No application found.")
ValueError: No application found.



Best regards,

Svenn.



More information about the Grok-dev mailing list