Bird
0
0

Which of the following best describes how you use an extension with the init_app pattern in a Flask app factory?

easy📝 Conceptual Q2 of 15
Flask - Middleware and Extensions
Which of the following best describes how you use an extension with the init_app pattern in a Flask app factory?
ACall <code>init_app()</code> before creating the Flask app instance.
BCreate the extension instance inside the factory function and return it.
CCreate the extension instance globally, then call <code>init_app(app)</code> inside the factory function.
DUse <code>init_app()</code> only if you have a single app instance.
Step-by-Step Solution
Solution:
  1. Step 1: Recognize the global extension instance

    Extensions are usually created once globally to avoid multiple instances and then initialized with the app inside the factory.
  2. Step 2: Understand the timing of init_app call

    The init_app(app) method must be called after the app instance is created, inside the factory function.
  3. Final Answer:

    Create the extension instance globally, then call init_app(app) inside the factory function. -> Option C
  4. Quick Check:

    Extension instance global + init_app inside factory = Create the extension instance globally, then call init_app(app) inside the factory function. [OK]
Quick Trick: Create extension once, init with app inside factory [OK]
Common Mistakes:
MISTAKES
  • Creating extension inside factory causing multiple instances
  • Calling init_app before app creation
  • Using init_app only for single app setups

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes