Complete the code to define the Flask application factory function.
from flask import Flask def create_app(): app = Flask(__name__) return [1]
The application factory function must return the Flask app instance it creates. Here, app is the Flask app object.
Complete the code to register a blueprint inside the application factory.
from flask import Flask, Blueprint bp = Blueprint('main', __name__) def create_app(): app = Flask(__name__) app.[1](bp) return app
add_blueprint.Flask apps use register_blueprint() to add blueprints for modular routes.
Fix the error in the application factory by completing the missing configuration line.
def create_app(): app = Flask(__name__) app.config['SECRET_KEY'] = [1] return app
SECRET_KEY to None or a variable name instead of a string.The SECRET_KEY must be a string used for security purposes. Here, a simple string is used.
Fill both blanks to create a dictionary comprehension that maps blueprint names to their URLs inside the factory.
def create_app(): app = Flask(__name__) blueprints = {'main': '/main', 'admin': '/admin'} urls = [1]: [2] for [1] in blueprints return app
The comprehension iterates over blueprint names and maps each name to its URL from the dictionary.
Fill all three blanks to complete the factory pattern that initializes extensions and registers blueprints.
from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() def create_app(): app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = [1] db.[2](app) from .main import bp as main_bp app.[3](main_bp) return app
The database URI is set to a SQLite file. The extension is initialized with init_app. The blueprint is registered with register_blueprint.