0PricingLogin
Flask Academy · Lesson

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 yet

All lessons in this course

  1. Problems with a Global app Object
  2. Write a create_app Function
  3. Init Extensions with init_app
  4. Register Blueprints in the Factory
← Back to Flask Academy