Flask app.before_request to ignore routes that don't exist

Viewed 310

For each request I am checking to see if the app is in maintenance mode, I am doing this because if there is some kind of bug I can easily put the app into this mode and it will inform the users of the state.

However, even when a route does not exist the before check is performed.

Is it possible to ignore this particular check when a route doesn't exist and for the fallback route to take over and inform the user it does not exit.

Before request maintenance check:

@app.before_request
def maintenance_mode():
    maintenance = yaml.safe_load(open(app.root_path + '/maintenance.yml'))
    if maintenance['status']:
        raise MaintenanceMode()

Fallback:

@app.route('/<path:fallback>')
def fallback_catcher(fallback):
    raise FallbackNotFound()
0 Answers
Related