官方cookbook http://webpy.org/cookbook/custom_notfound.zh-cn
import web
urls = (
#'/(hello)', 'hello' #test for notfound
'/hello', 'hello' #test for internalerror
)
class hello:
def GET(self, name):
if not name:
name = 'World'
return 'Hello, ' + name + '!'
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()))
def internalerror():
return web.internalerror("Bad, bad server. No donut for you.")
if __name__ == "__main__":
app = web.application(urls, globals())
app.notfound = notfound
app.internalerror = internalerror
app.run()
感觉这个很好用啊
为什么越学越觉得java很笨重?
本文介绍了一个使用WebPy框架的简单示例,演示了如何自定义404和500错误页面。通过覆盖应用实例的notfound和internalerror方法,可以返回定制化的错误信息。
1020

被折叠的 条评论
为什么被折叠?



