0
0
Flaskframework~10 mins

Application factory pattern deep dive in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the Flask application factory function.

Flask
from flask import Flask

def create_app():
    app = Flask(__name__)
    return [1]
Drag options to blanks, or click blank then click option'
Acreate_app
BFlask
CNone
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the Flask class instead of the app instance.
Not returning anything from the function.
2fill in blank
medium

Complete the code to register a blueprint inside the application factory.

Flask
from flask import Flask, Blueprint

bp = Blueprint('main', __name__)

def create_app():
    app = Flask(__name__)
    app.[1](bp)
    return app
Drag options to blanks, or click blank then click option'
Aadd_blueprint
Bregister_blueprint
Cinclude_blueprint
Dattach_blueprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like add_blueprint.
Forgetting to register the blueprint.
3fill in blank
hard

Fix the error in the application factory by completing the missing configuration line.

Flask
def create_app():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = [1]
    return app
Drag options to blanks, or click blank then click option'
A'mysecretkey'
BNone
C12345
DSECRET_KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Setting SECRET_KEY to None or a variable name instead of a string.
Using an integer without quotes.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps blueprint names to their URLs inside the factory.

Flask
def create_app():
    app = Flask(__name__)
    blueprints = {'main': '/main', 'admin': '/admin'}
    urls = [1]: [2] for [1] in blueprints
    return app
Drag options to blanks, or click blank then click option'
Aname
Burl
Cblueprints[name]
Dblueprints
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dictionary name as the key or value directly.
Mixing up keys and values in the comprehension.
5fill in blank
hard

Fill all three blanks to complete the factory pattern that initializes extensions and registers blueprints.

Flask
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
Drag options to blanks, or click blank then click option'
A'sqlite:///app.db'
Binit_app
Cregister_blueprint
D'postgresql://user@localhost/db'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong method to initialize the extension.
Forgetting to register the blueprint.
Setting the database URI incorrectly.