how to call @app.before_request how to call @app.before_request flask flask

how to call @app.before_request


If you would give some code maybe it will be better to understand your question, but if I understand it right you want to render template right before the request?

before_request is used to call some function or do some action before the request. So basically it is for preparing your app to deal with the request which comes. Example: initialize database connection and put it in g object for later access.

Example of before_request usage (like initialize DB for example) is:

@app.before_requestdef before_request():    g.db = connect_db()

If you use it as @app.before_request so it is decorator. Something more could be found in Flask docs

But another thing is why you want render_template right before request? I think that you should render templates in the views not in this place. You let the request reach your app, your view and then render template there.