Error pages for each page

I have a bulb application that looks something like this:

app.py
blueprints/
    www.py
    shop.py

app.pyimports drawing objects from each of the files in the directory blueprintsand registers them with the object Flaskin app.pywith the corresponding subdomain (also imported from the file). Each drawing registers error handlers, however, they are only called when the view manually causes abort(), rather than general errors (i.e., invoking a nonexistent URL in a subdomain that is managed shop.pyinstead calls the error handler on app.py).

Is there a way to get the flask to pass errors to a project that processes the subdomain in which this error occurs?

+4
source share
2 answers

The flask documentation says this is not possible for 404s and 500s. If you need this functionality, you can use a wildcard in your project to handle 404s:

@a_blueprint.route("<path:invalid_path>")
def missing_resource(invalid_path):
    return "There isn't anything at " + invalid_path, 404
+4
source

You can use current_app and put it in the drawings. Sort of:

shop.py

from flask import current_app

@current_app.errorhandler(404)
def page_not_found(e):
return redirect(url_for('shop.index'))
-1
source

All Articles