|
|
@ -245,4 +245,22 @@ Here is an example for a "404 Page Not Found" exception:: |
|
|
|
def page_not_found(e): |
|
|
|
def page_not_found(e): |
|
|
|
return render_template('pages/404.html') |
|
|
|
return render_template('pages/404.html') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Most errorhandlers will simply work as expected; however, there is a caveat |
|
|
|
|
|
|
|
concerning handlers for 404 and 405 exceptions. These errorhandlers are only |
|
|
|
|
|
|
|
invoked from an appropriate ``raise`` statement or a call to ``abort`` in another |
|
|
|
|
|
|
|
of the blueprint's view functions; they are not invoked by, e.g., an invalid URL |
|
|
|
|
|
|
|
access. This is because the blueprint does not "own" a certain URL space, so |
|
|
|
|
|
|
|
the application instance has no way of knowing which blueprint errorhandler it |
|
|
|
|
|
|
|
should run if given an invalid URL. If you would like to execute different |
|
|
|
|
|
|
|
handling strategies for these errors based on URL prefixes, they may be defined |
|
|
|
|
|
|
|
at the application level using the ``request`` proxy object:: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(404) |
|
|
|
|
|
|
|
@app.errorhandler(405) |
|
|
|
|
|
|
|
def _handle_api_error(ex): |
|
|
|
|
|
|
|
if request.path.startswith('/api/'): |
|
|
|
|
|
|
|
return jsonify_error(ex) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
return ex |
|
|
|
|
|
|
|
|
|
|
|
More information on error handling see :ref:`errorpages`. |
|
|
|
More information on error handling see :ref:`errorpages`. |
|
|
|