Recall & Review
beginner
What is the Application Factory pattern in Flask?
It is a way to create Flask application instances inside a function. This allows you to configure and initialize the app dynamically, making it easier to manage different environments and testing.
Click to reveal answer
beginner
Why use the Application Factory pattern instead of creating a Flask app globally?
Using the factory pattern helps avoid issues with global state, supports multiple app instances, and improves testing by allowing fresh app creation with different settings each time.
Click to reveal answer
intermediate
How do you register extensions like SQLAlchemy in the Application Factory pattern?
You create the extension object outside the factory function without binding it to an app. Then inside the factory, you call the extension's init_app(app) method to bind it to the current app instance.
Click to reveal answer
intermediate
What is the role of Blueprints in the Application Factory pattern?
Blueprints let you organize your app into reusable components. In the factory pattern, you register blueprints inside the factory function to attach routes and views to the app instance.Click to reveal answer
beginner
How does the Application Factory pattern improve testing in Flask?
It allows tests to create a new app instance with specific configurations for each test, avoiding shared state and making tests isolated and reliable.
Click to reveal answer
What is the main benefit of using an application factory in Flask?
✗ Incorrect
The factory pattern allows creating multiple app instances with different configurations, which is useful for testing and different environments.
Where do you call init_app() for Flask extensions in the factory pattern?
✗ Incorrect
Extensions are initialized inside the factory function by calling init_app(app) after the app instance is created.
How do Blueprints relate to the application factory pattern?
✗ Incorrect
Blueprints are registered inside the factory function to organize routes and views for the app instance.
Which of these is NOT a benefit of the application factory pattern?
✗ Incorrect
The factory pattern does not remove configuration; it helps manage it better but does not simplify deployment by removing config.
What is a common first step inside an application factory function?
✗ Incorrect
The factory function starts by creating the Flask app instance, then configures it and registers components.
Explain how the Application Factory pattern works in Flask and why it is useful.
Think about how you create the app inside a function instead of globally.
You got /5 concepts.
Describe how Flask extensions and Blueprints are used within the Application Factory pattern.
Focus on where and how extensions and Blueprints connect to the app.
You got /4 concepts.