Bird
0
0

When using the Flask application factory pattern to support both testing and production configurations, which method is recommended?

hard📝 Conceptual Q8 of 15
Flask - Ecosystem and Patterns
When using the Flask application factory pattern to support both testing and production configurations, which method is recommended?
AUse global variables to switch configurations after app creation
BCreate separate factory functions for testing and production apps
CHardcode all configurations inside the factory function
DPass a config object or name to the factory and load settings accordingly inside create_app()
Step-by-Step Solution
Solution:
  1. Step 1: Understand config management

    The factory pattern supports passing configuration parameters to create_app() to select environment settings.
  2. Step 2: Evaluate options

    Pass a config object or name to the factory and load settings accordingly inside create_app() is best practice: pass config name or object and load config inside factory.
  3. Step 3: Eliminate others

    Create separate factory functions for testing and production apps duplicates code. Hardcode all configurations inside the factory function reduces flexibility. Use global variables to switch configurations after app creation uses globals, which is error-prone.
  4. Final Answer:

    Pass a config object or name to the factory and load settings accordingly inside create_app() -> Option D
  5. Quick Check:

    Is config passed and loaded inside factory? Yes. [OK]
Quick Trick: Pass config to factory, load inside create_app() [OK]
Common Mistakes:
MISTAKES
  • Creating multiple factory functions unnecessarily
  • Hardcoding configs reducing flexibility
  • Using globals to switch configs after creation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes