Init Extensions with init_app
Defer extension binding until app creation.
The Extension Dilemma
Extensions like SQLAlchemy used to take the app right away. Inside a factory that does not work, because the app does not exist at import time yet. 🤔
Create Without an App
The fix is two steps. First, create the extension object at module level with no app passed in. It stays unbound for now.
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy() # no app yetAll lessons in this course
- Problems with a Global app Object
- Write a create_app Function
- Init Extensions with init_app
- Register Blueprints in the Factory