Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

42 lines (26 sloc) 0.931 kB
layout title
default
Custom NotFound message

Custom NotFound message

Other languages: français | ...

Problem

How to customize notfound and other messages?

Solution

import web

urls = (...)
app =  web.application(urls, globals())

def notfound():
    return web.notfound("Sorry, the page you were looking for was not found.")

    # You can use template result like below, either is ok:
    #return web.notfound(render.notfound())
    #return web.notfound(str(render.notfound()))

app.notfound = notfound

And to return the custom 404 from your code, just do:

class example:
    def GET(self):
        raise web.notfound()

In the same way InternalError message can also be customized.

def internalerror():
    return web.internalerror("Bad, bad server. No donut for you.")

app.internalerror = internalerror
Jump to Line
Something went wrong with that request. Please try again.