Bird
0
0

What will happen if you call create_app() twice with different configs in this pattern?

medium📝 component behavior Q5 of 15
Flask - Ecosystem and Patterns
What will happen if you call create_app() twice with different configs in this pattern?
def create_app(config_name):
    app = Flask(__name__)
    if config_name == 'dev':
        app.config['DEBUG'] = True
    else:
        app.config['DEBUG'] = False
    return app

app1 = create_app('dev')
app2 = create_app('prod')

What is app2.config['DEBUG']?
ANone
BTrue
CFalse
DRaises an error
Step-by-Step Solution
Solution:
  1. Step 1: Understand config logic in factory

    If config_name is 'dev', DEBUG is True; otherwise False.
  2. Step 2: Check app2 creation with 'prod'

    Since 'prod' is not 'dev', DEBUG is set to False for app2.
  3. Final Answer:

    False -> Option C
  4. Quick Check:

    app2 DEBUG config = False [OK]
Quick Trick: Each app instance has its own config [OK]
Common Mistakes:
MISTAKES
  • Assuming app2 inherits app1 config
  • Expecting True for all instances
  • Thinking config keys are shared globally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes