How do I exclude certain functions from my app.before_request
function. I know you can check request.endpoint
, but I would like to have this functionality using decorators. Any ideas?
Asked
Active
Viewed 5,377 times
2

Panda
- 690
- 1
- 6
- 19
-
May be you can use `before_request_funcs` check out here - http://flask.pocoo.org/docs/0.12/api/#flask.Flask.before_request_funcs – SRC Jun 09 '17 at 12:35
-
2And probably another solution [here](https://stackoverflow.com/questions/19574694/flask-hit-decorator-before-before-request-signal-fires) – SRC Jun 09 '17 at 12:39
-
That second solution should work thank you. – Panda Jun 09 '17 at 12:42
-
you are welcome :). Added as a small answer with an explanation – SRC Jun 09 '17 at 12:42
1 Answers
3
This has a solution here already - Flask hit decorator before before_request signal fires
What basically you end up doing is to define a normal function where you set the exclusion flag and then add it as decorator to all the routes you do not want to be included in the before_request call and then in your before_request where you check for the presence of that said exclusion flag and do things accordingly.

SRC
- 2,123
- 3
- 31
- 44
-
The key point to that referenced answer, is that you can get the current view function in `@app.before_request` with `view_func = app.view_functions[request.endpoint]` – Panda Jun 09 '17 at 12:54