python - Application-wide request hooks in Flask. How to implement? -


is ok define shared request hook inside application factory?

def create_app(config_name):      app = flask(__name__)     app.config.from_object(config[config_name])      db.init_app(app)     csrf.init_app(app)     login_manager.init_app(app)     babel.init_app(app)      @app.before_request     def before_request_callback():         if request.view_args , 'locale' in request.view_args:             if request.view_args['locale'] not in app.config['supported_locales']:                 return abort(404)             g.locale = request.view_args['locale']             request.view_args.pop('locale')      . app_area__main import main main_blueprint     app.register_blueprint(main_blueprint)      . app_area__admin import admin admin_blueprint     app.register_blueprint(admin_blueprint, url_prefix='/admin')         

just register function before_app_request in main(app_area_main) blueprint. example:

@main_blueprint.before_app_request def before_app_request():     pass 

all request pass app invoke function.

check link api of blueprint in flask.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -