Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom error pages with app.yaml for Google Appengine Python

For a Google Appengine project written in Python, I want to have my own error messages when an error occurs. I want to use the error_handlers as described in: http://code.google.com/intl/nl/appengine/docs/python/config/appconfig.html#Custom_Error_Responses

In the application I use webapp with debug = False

When I create an error in my code, I get the standard 500 Server error message from the browser.

I have created a custom error page named default_error.html

The question is: Where to save this custom error page?

BTW This is my app.yaml code:

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
like image 618
Hans Avatar asked Jan 22 '12 21:01

Hans


1 Answers

Defining a custom 404 with just the python part works for me:

app.error_handlers[404] = handle_404

def handle_404(request, response, exception):
    c = {'exception': exception.status}
    t = jinja2.get_jinja2(app=app).render_template('404.html', **c)
    response.write(t)
    response.set_status(exception.status_int)

This gives you more control over error messages and other dynamics that you might want to display.

like image 155
Niklas Rosencrantz Avatar answered Oct 15 '22 00:10

Niklas Rosencrantz