cookiecutter-flask/cookiecutter-flask

Need some help

govindkelkar opened this issue · 4 comments

How to use before_request in this setup?
How to get the '@app' working?

Hi @govindkelkar, I don't have enough context to be able to help with your question. This isn't specific to the flask-cookiecutter project, it's more of a general Flask question that would be better answered on StackOverflow or using one of the supported resources for Flask questions.

If you're looking for a usage example, here is one from the Flask docs: https://flask.palletsprojects.com/en/1.1.x/patterns/deferredcallbacks/

In the link provided by you the app is already exposed.
in flask-cookiecutter the app is created using create_app().
My problem is from where to import the app?

This post should help: https://stackoverflow.com/questions/13657711/where-do-i-put-my-blueprint-before-request

Instead of registering the before_request function with the app, instead register it with one of the app's blueprints. But when you do this, the function will only execute before requests that come from views registered with the specific blueprint.

Sorry for the late reply from me.
I was held up because of flask-seasurf package as it needs to execute a method with @app.before_request decorator. As I was trying to use this decorator it gave the error saying app is not defined.
So my problem was how to get the app reference out of create_app() method. This requirement remained un-resolved.
Finaly I used the flask-paranoid with CSRFProtect package.