Web.py配置自定义404和500错误信息

Web.py如何自定义Http404和Http500错误信息?


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

在代码中raise web.notfound()即可


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

同理可自定义InternalError信息:


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

app.internalerror = internalerror

本文链接:http://bookshadow.com/weblog/2014/03/08/webpy-404-500/
请尊重作者的劳动成果,转载请注明出处!书影博客保留对文章的所有权利。

如果您喜欢这篇博文,欢迎您捐赠书影博客: ,查看支付宝二维码