[Twisted-web] [version not trashed by enigmail] Custom 404, 500 pages ...

Cory Dodt corydodt at twistedmatrix.com
Thu Nov 11 14:33:48 MST 2004

Cory Dodt wrote:
> On the Wiki, I posted (quite some time ago) a working example of putting 
> your
> own 404 and 500 pages in place of the plain-jane defaults.  The example 
> still
> works, and is at:
> http://divmod.org/users/wiki.twistd/nevow/moin.cgi/Custom404Page
> -=-=-
> However, at the same time I wrote that, I discovered that I cannot 
> satisfy my
> own use case, which is custom error pages built with xml*, because of 
> some bug
> in how Nevow selects the page context to render.  I have tried to find a 
> patch
> for this myself, but it just isn't happening.  Too much about context is 
> still
> mysterious to me :-/
> Compare the minimal example below to the wiki page above.  The wiki works,
> this one does not.  When you visit OopsPage, you should see a link to 
> take you
> back to the root page.  Instead, in that spot you get an error message 
> saying
> render_lastLink can't be found.
> Thanks for looking :-)
> -=-=-

from nevow import appserver, rend, loaders, tags as T, inevow
from twisted.application import service, internet

class The500Page(rend.Page):
     __implements__ = (inevow.ICanHandleException,)
     docFactory = loaders.xmlstr("""\
<html xmlns:n="http://nevow.com/ns/nevow/0.1">
         <title>500 error</title>
         <h1>Ouchie.  Server error.</h1>
         <p>The server is down.</p>
         <p>Ohhh, the  server.</p>
         <p n:render="lastLink" />

     def renderHTTP_exception(self, ctx, failure):
     def render_lastLink(ctx, data):
         referer = inevow.IRequest(ctx).getHeader('referer')
         if referer:
             return T.p[T.a(href=referer)['This link'],
                        ' will return you to the last page you were on.']
             return T.p['You seem to be hopelessly lost.']

the500page = The500Page()

class OopsPage(rend.Page):
     def exception(self, ctx, data):
         1/0 # cause an exception on purpose
     docFactory = loaders.stan(exception)

More information about the Twisted-web mailing list