How to use an authentication decorator from within a blueprint in flask How to use an authentication decorator from within a blueprint in flask flask flask

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:

  1. app.py (instantiate app & db)
  2. auth.py (instantiate auth, imports from app.py)
  3. api.py (instantiate api, imports from app.py)
  4. decorators.py (define requires_auth, imports from auth and api)
  5. blueprints/views.py (imports from app.py, auth.py, api.py, decorators.py)
  6. main.py (imports app, auth, api, decorators, blueprints) and is entry-point for application.