0
0
Flaskframework~10 mins

Application factory pattern 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 import the Flask class correctly.

Flask
from flask import [1]

def create_app():
    app = [1](__name__)
    return app
Drag options to blanks, or click blank then click option'
AFlask
Bflask
CApp
Dapplication
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'flask' instead of 'Flask'
Importing 'App' or 'application' which do not exist
2fill in blank
medium

Complete the code to define the application factory function name correctly.

Flask
def [1]():
    app = Flask(__name__)
    return app
Drag options to blanks, or click blank then click option'
Acreate_app
Binit_app
Cmake_app
Dstart_app
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'init_app' which is usually a method, not the factory function
Using 'start_app' or 'make_app' which are not standard names
3fill in blank
hard

Fix the error in the code to register a blueprint inside the factory function.

Flask
def create_app():
    app = Flask(__name__)
    from .views import main
    app.[1](main)
    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 'add_blueprint' which does not exist
Using 'include_blueprint' or 'attach_blueprint' which are invalid
4fill in blank
hard

Fill both blanks to configure the app with a secret key and enable debug mode.

Flask
def create_app():
    app = Flask(__name__)
    app.config['[1]'] = '[2]'
    app.config['DEBUG'] = True
    return app
Drag options to blanks, or click blank then click option'
ASECRET_KEY
BDATABASE_URI
Cmysecretkey
Dproductionkey
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'DATABASE_URI' instead of 'SECRET_KEY' for the config key
Using 'productionkey' which is less common for examples
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps blueprint names to their url prefixes.

Flask
blueprints = {
    '[1]': [2].url_prefix for [3] in app.blueprints.values()
}
Drag options to blanks, or click blank then click option'
Abp.name
Bbp
Dblueprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'blueprint' as the loop variable which is less common
Using incorrect keys or values that do not exist on blueprint objects