0
0
Flaskframework~10 mins

Application factory pattern preview 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'
AFlask
Bapp
Ccreate_app
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the Flask class instead of the app instance.
Forgetting to return 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'
Aregister_blueprint
Badd_url_rule
Crun
Dinit_app
Attempts:
3 left
💡 Hint
Common Mistakes
Using add_url_rule instead of register_blueprint.
Calling run inside the factory.
3fill in blank
hard

Fix the error in the application factory by completing the code to load configuration from a file.

Flask
def create_app():
    app = Flask(__name__)
    app.config.[1]('config.py')
    return app
Drag options to blanks, or click blank then click option'
Afrom_pyfile
Bload_config
Cload_from_file
Dread_config
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like load_config.
Trying to assign config directly without using a method.
4fill in blank
hard

Fill both blanks to create a route inside a blueprint and return a greeting.

Flask
from flask import Blueprint

bp = Blueprint('main', __name__)

@bp.route([1])
def hello():
    return [2]
Drag options to blanks, or click blank then click option'
A"/"
B"Hello, Flask!"
C"/home"
D"Welcome!"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong route path like "/home" when root is expected.
Returning a variable instead of a string.
5fill in blank
hard

Fill all three blanks to create an application factory that registers a blueprint and loads config.

Flask
from flask import Flask, Blueprint

bp = Blueprint('main', __name__)

@bp.route("/")
def index():
    return "Welcome!"

def create_app():
    app = Flask(__name__)
    app.config.[1]('config.py')
    app.[2](bp)
    return [3]
Drag options to blanks, or click blank then click option'
Afrom_pyfile
Bregister_blueprint
Capp
Dload_config
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names for config loading or blueprint registration.
Forgetting to return the app instance.