Bird
0
0

In the application factory pattern, where should extensions like SQLAlchemy be initialized?

easy📝 Conceptual Q2 of 15
Flask - Ecosystem and Patterns
In the application factory pattern, where should extensions like SQLAlchemy be initialized?
AOutside the factory function without binding to app
BInside the factory function after creating the app
CInside the factory function before creating the app
DOnly in the main script, never in the factory
Step-by-Step Solution
Solution:
  1. Step 1: Recall extension initialization best practice

    Extensions should be created outside the factory function without app binding, then initialized with app inside the factory.
  2. Step 2: Match options to this pattern

    Outside the factory function without binding to app correctly states extensions are created outside without binding. Inside the factory function after creating the app is wrong because initialization happens inside, but creation is outside. Options C and D are incorrect.
  3. Final Answer:

    Outside the factory function without binding to app -> Option A
  4. Quick Check:

    Extension creation location = B [OK]
Quick Trick: Create extensions outside, init inside factory [OK]
Common Mistakes:
MISTAKES
  • Creating and binding extensions inside factory directly
  • Initializing extensions before app creation
  • Placing extension code only in main script

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes