The factory function should create and return a new Flask app instance.
Step 2: Analyze options
def create_app():
app = Flask(__name__)
return app defines create_app() that creates and returns a Flask app correctly.
Step 3: Eliminate incorrect options
app = Flask(__name__)
def create_app():
return app creates app outside the function, not a factory. def create_app(app):
app = Flask(__name__)
return app has an unused parameter and reassigns app. def create_app():
return Flask returns the Flask class, not an instance.
Final Answer:
def create_app():
app = Flask(__name__)
return app -> Option A
Quick Check:
Function creates and returns app instance? Yes. [OK]
Quick Trick:Factory must create and return new app instance [OK]
Common Mistakes:
MISTAKES
Defining app globally instead of inside factory
Returning Flask class instead of instance
Including unnecessary parameters in factory
Master "Ecosystem and Patterns" in Flask
9 interactive learning modes - each teaches the same concept differently