0
0
Flaskframework~10 mins

Blueprint creation and registration 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 create a Flask blueprint named 'auth'.

Flask
from flask import Blueprint

auth = Blueprint('[1]', __name__)
Drag options to blanks, or click blank then click option'
Aapp
Bauth
Cmain
Dblueprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using the app name instead of the blueprint name.
Using '__name__' as the first argument instead of the blueprint name.
2fill in blank
medium

Complete the code to register the 'auth' blueprint with the Flask app.

Flask
from flask import Flask

app = Flask(__name__)
app.[1](auth)
Drag options to blanks, or click blank then click option'
Aregister_blueprint
Badd_blueprint
Cinclude_blueprint
Dattach_blueprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'add_blueprint'.
Trying to assign the blueprint directly to the app.
3fill in blank
hard

Fix the error in the blueprint route decorator to use the correct blueprint name.

Flask
from flask import Blueprint

auth = Blueprint('auth', __name__)

@[1].route('/login')
def login():
    return 'Login Page'
Drag options to blanks, or click blank then click option'
Aapp
Bblueprint
Cflask
Dauth
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app.route' inside blueprint code.
Using an undefined variable for the decorator.
4fill in blank
hard

Fill both blanks to create and register a blueprint named 'blog' with the Flask app.

Flask
from flask import Flask, Blueprint

app = Flask(__name__)
blog = Blueprint('[1]', __name__)
app.[2](blog)
Drag options to blanks, or click blank then click option'
Ablog
Bmain
Cregister_blueprint
Dadd_blueprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'main' instead of 'blog' as the blueprint name.
Using a wrong method like 'add_blueprint' to register.
5fill in blank
hard

Fill all three blanks to define a blueprint named 'shop', add a route '/items', and register it with the app.

Flask
from flask import Flask, Blueprint

app = Flask(__name__)
shop = Blueprint('[1]', __name__)

@shop.route('[2]')
def items():
    return 'Shop Items'

app.[3](shop)
Drag options to blanks, or click blank then click option'
Ashop
B/items
Cregister_blueprint
D/products
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different route path like '/products'.
Forgetting to register the blueprint with the app.