Skip to content
Myr

Mention existence of register_error_handler in errorpages.rst

Before adoption: this commit came in with the history the project adopted, so no landing records it.

See https://github.com/pallets/flask/issues/1837 for context.

authored by Benjamin Liebald · committed by David Lord · parent 39d5552 · Browse files · 1 file+17 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−3 removed

  • other:+17 added−3 removed

1 file+17 added−3 removed

modified:docs/patterns/errorpages.rst+17 added-3 removed
52 unmodified lines
53can be a different error: a handler for internal server errors will be54passed other exception instances as well if they are uncaught.5556An error handler is registered with the :meth:`~flask.Flask.errorhandler`57decorator and the error code of the exception. Keep in mind that Flask58will *not* set the error code for you, so make sure to also provide the59HTTP status code when returning a response.57decorator and the error code of the exception (alternatively, you can use the58:meth:`~flask.Flask.register_error_handler` function, e.g., when you're59registering error handlers as part of your Application Factory). Keep in mind60that Flask will *not* set the error code for you, so make sure to also provide61the HTTP status code when returning a response.delete_cookie.6263Please note that if you add an error handler for "500 Internal Server64Error", Flask will not trigger it if it's running in Debug mode.65
4 unmodified lines
70 @app.errorhandler(404)71 def page_not_found(e):72 return render_template('404.html'), 4047374And, using an application factory pattern (see :ref:`app-factories`)::7576 from flask import Flask, render_template77 78 def page_not_found(e):79 return render_template('404.html'), 40480 81 def create_app(config_filename):82 app = Flask(__name__)83 # ...84 app.register_error_handler(404, page_not_found)8586An example template might be this:8788.. sourcecode:: html+jinja89
8 unmodified lines