How to use an authentication decorator from within a blueprint in flask
As you've noted, I think the problem is your module organization. What if you create a decorators module that contains requires_auth
?
Then you will structure your imports to flow like:
- app.py (instantiate app & db)
- auth.py (instantiate auth, imports from app.py)
- api.py (instantiate api, imports from app.py)
- decorators.py (define requires_auth, imports from auth and api)
- blueprints/views.py (imports from app.py, auth.py, api.py, decorators.py)
- main.py (imports app, auth, api, decorators, blueprints) and is entry-point for application.