您的位置:首页 > 其它

Web.py Cookbook 简体中文版 - 自定义NotFound消息

2012-11-26 10:08 507 查看

问题

如何定义NotFound消息和其他消息?

解法

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

要返回自定义的NotFound消息,这么做即可:

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

也可以用同样的方法自定义500错误消息:

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

app.internalerror = internalerror
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: