如何使用适用于Google Appengine Python的app.yaml创建自定义错误页面

Han*_*ans 6 python google-app-engine

对于使用Python编写的Google Appengine项目,我希望在发生错误时拥有自己的错误消息.我想使用error_handlers,如下所述:http: //code.google.com/intl/nl/appengine/docs/python/config/appconfig.html#Custom_Error_Responses

在应用程序中我使用webapp debug = False

当我在代码中创建错误时,我从浏览器中收到标准的500 Server错误消息.

我创建了一个名为的自定义错误页面 default_error.html

问题是:在哪里保存此自定义错误页面?

BTW这是我的app.yaml代码:

application: customerrorpage
version: 1
runtime: python
api_version: 1


error_handlers:
- file: default_error.html

handlers:
- url: /good.htm
  static_files: static/good.htm
  upload: static/good.htm

- url: /
  static_files: static/good.htm
  upload: static/good.htm

- url: /.*
  script: main.py
Run Code Online (Sandbox Code Playgroud)

Amy*_* U. 0

解决这个问题的一种方法是定义一个“BaseRequestHandler”类,您的请求处理程序是从该类派生的。BaseRequestHandler 类可以重写 handle_exception() 方法(请参阅http://code.google.com/appengine/docs/python/tools/webapp/requesthandlerclass.html#RequestHandler_handle_exception)以呈现错误页面。