Skip to content
Browse files

edit

  • Loading branch information...
1 parent b1541dc commit 73d2d5d077a72af39a6d8f430589ec8d28aa83f4 @ohsc ohsc committed with anandology Jan 20, 2010
Showing with 40 additions and 0 deletions.
  1. +40 −0 cookbook/custom_notfound.zh-cn.md
View
40 cookbook/custom_notfound.zh-cn.md
@@ -0,0 +1,40 @@
+---
+layout: default
+title: 自定义NotFound消息
+---
+
+# 自定义NotFound消息
+
+## 问题
+
+如何定义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

0 comments on commit 73d2d5d

Please sign in to comment.
Something went wrong with that request. Please try again.