0
0
Flaskframework~10 mins

Blueprint best practices 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'
Aauth
Bapp
Cmain
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name than the variable name causes confusion.
Leaving the name blank or misspelled.
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, url_prefix='/auth')
Drag options to blanks, or click blank then click option'
Aregister_blueprint
Battach_blueprint
Cinclude_blueprint
Dadd_blueprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'add_blueprint'.
Forgetting to register the blueprint causes routes not to work.
3fill in blank
hard

Fix the error in the blueprint route definition to return 'Hello Auth!'.

Flask
from flask import Blueprint

auth = Blueprint('auth', __name__)

@auth.route('/hello')
def [1]():
    return 'Hello Auth!'
Drag options to blanks, or click blank then click option'
Aauth
Bhello
Cindex
Dhome
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name unrelated to the route can confuse readers.
Leaving the function name blank or using reserved words.
4fill in blank
hard

Fill both blanks to create a blueprint with a URL prefix and import it in the app.

Flask
from flask import Flask
from [1] import auth

app = Flask(__name__)
app.[2](auth, url_prefix='/auth')
Drag options to blanks, or click blank then click option'
Aauth_blueprint
Bregister_blueprint
Cblueprints
Dadd_blueprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong module names or method names.
Forgetting the URL prefix when registering the blueprint.
5fill in blank
hard

Fill all three blanks to define a blueprint, add a route, and register it with the app.

Flask
from flask import Flask, Blueprint

app = Flask(__name__)

api = Blueprint('[1]', __name__)

@api.route('/status')
def [2]():
    return 'API is running'

app.[3](api, url_prefix='/api')
Drag options to blanks, or click blank then click option'
Aapi
Bstatus
Cregister_blueprint
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent names for blueprint and variable.
Using wrong method to register the blueprint.
Naming the route function unrelated to the route.