How to create custom error pages using 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 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 a 500 server error message from the server in the browser.

I created a custom error page called default_error.html

Question: where to save this user 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 
+6
source share
3 answers

Defining a custom 404 using only the python part 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 can display.

+4
source

One way to approach this is to define the BaseRequestHandler class from which your request handlers are subclasses. The BaseRequestHandler class can override the handle_exception () method (see http://code.google.com/appengine/docs/python/tools/webapp/requesthandlerclass.html#RequestHandler_handle_exception ) to display the error page.

0
source

Partially found how it works. Thank you all for your answers.

The location of the HTM file can be in the kernel or in a separate directory. If this case uses, for example, the following code in the app.yaml file:

 error_handlers: - file: error_handlers/default_error.html 

The displayed html file should now be placed in the error_handlers directory

When importing a nonexistent module into main.py, the page above is shown.

To get a 500 error, I used webapp2 to display a custom error page. This page is always displayed when an error occurs. Even when there is an over_quota error, and app.yaml is correctly configured. I also uninstalled webapp2 and used webapp again. Now no pages are displayed at all.

I have another application that is currently over_quote. How to display html over_quota page? This is mistake?

0
source

Source: https://habr.com/ru/post/906605/


All Articles