0
0
Flaskframework~10 mins

Namespace concept 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 'admin'.

Flask
from flask import Blueprint
admin_bp = Blueprint('[1]', __name__)
Drag options to blanks, or click blank then click option'
Auser
Badmin
Cmain
Dapi
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name that doesn't match the namespace purpose.
2fill in blank
medium

Complete the code to register the 'admin' Blueprint with the Flask app under the URL prefix '/admin'.

Flask
from flask import Flask
app = Flask(__name__)
app.register_blueprint(admin_bp, url_prefix='[1]')
Drag options to blanks, or click blank then click option'
A/api
B/user
C/main
D/admin
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the slash or using a wrong prefix.
3fill in blank
hard

Fix the error in the route decorator to use the 'admin' Blueprint instead of the Flask app.

Flask
@[1].route('/dashboard')
def dashboard():
    return 'Admin Dashboard'
Drag options to blanks, or click blank then click option'
Aadmin_bp
Bblueprint
Cflask
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app.route' instead of 'admin_bp.route'.
4fill in blank
hard

Fill both blanks to create a Blueprint named 'api' and register it with the app under '/api'.

Flask
api_bp = Blueprint('[1]', __name__)
app.register_blueprint([2], url_prefix='/api')
Drag options to blanks, or click blank then click option'
Aapi
Badmin_bp
Capi_bp
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the Blueprint name and variable.
5fill in blank
hard

Fill all three blanks to define a route '/status' in the 'api' Blueprint that returns JSON with a status message.

Flask
from flask import jsonify

@[1].route('[2]')
def status():
    return jsonify({{'status': '[3]'}})
Drag options to blanks, or click blank then click option'
Aapi_bp
B/status
Cok
Dadmin_bp
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong Blueprint or incorrect route path.