Skip to content
This repository
Browse code

edit

  • Loading branch information...
commit 73d2d5d077a72af39a6d8f430589ec8d28aa83f4 1 parent b1541dc
吼吼 / Chao Shen ohsc authored anandology committed

Showing 1 changed file with 40 additions and 0 deletions. Show diff stats Hide diff stats

  1. +40 0 cookbook/custom_notfound.zh-cn.md
40 cookbook/custom_notfound.zh-cn.md
Source Rendered
... ... @@ -0,0 +1,40 @@
  1 +---
  2 +layout: default
  3 +title: 自定义NotFound消息
  4 +---
  5 +
  6 +# 自定义NotFound消息
  7 +
  8 +## 问题
  9 +
  10 +如何定义NotFound消息和其他消息?
  11 +
  12 +## 解法
  13 +
  14 + import web
  15 +
  16 + urls = (...)
  17 + app = web.application(urls, globals())
  18 +
  19 + def notfound():
  20 + return web.notfound("Sorry, the page you were looking for was not found.")
  21 +
  22 + # You can use template result like below, either is ok:
  23 + #return web.notfound(render.notfound())
  24 + #return web.notfound(str(render.notfound()))
  25 +
  26 + app.notfound = notfound
  27 +
  28 +
  29 +要返回自定义的NotFound消息,这么做即可:
  30 +
  31 + class example:
  32 + def GET(self):
  33 + raise web.notfound()
  34 +
  35 +也可以用同样的方法自定义500错误消息:
  36 +
  37 + def internalerror():
  38 + return web.internalerror("Bad, bad server. No donut for you.")
  39 +
  40 + app.internalerror = internalerror

0 comments on commit 73d2d5d

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