0
0
Flaskframework~10 mins

Blueprint static files 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 with a static folder named 'static'.

Flask
from flask import Blueprint

bp = Blueprint('main', __name__, static_folder=[1])
Drag options to blanks, or click blank then click option'
A'static'
B'templates'
C'assets'
D'public'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'templates' instead of 'static' for static_folder
Forgetting to add quotes around the folder name
2fill in blank
medium

Complete the code to register the blueprint with the Flask app and serve static files under the URL prefix '/main'.

Flask
from flask import Flask

app = Flask(__name__)
app.register_blueprint(bp, url_prefix=[1])
Drag options to blanks, or click blank then click option'
A'/main'
B'/static'
C'/assets'
D'/public'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/static' as url_prefix which conflicts with default static path
Omitting the quotes around the prefix string
3fill in blank
hard

Fix the error in the blueprint static file URL generation code.

Flask
from flask import url_for

static_url = url_for('[1].static', filename='style.css')
Drag options to blanks, or click blank then click option'
Aapp
Bstatic
Cmain
Dbp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'static.static' or 'app.static' instead of the blueprint name
Leaving the blueprint name as a variable instead of a string
4fill in blank
hard

Fill both blanks to define a route in the blueprint that serves a static file URL for 'logo.png'.

Flask
from flask import Blueprint, url_for

bp = Blueprint('assets', __name__, static_folder='static')

@bp.route('/logo')
def logo():
    return url_for('[1].static', filename=[2])
Drag options to blanks, or click blank then click option'
Aassets
Bmain
C'logo.png'
D'style.css'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong blueprint name in url_for
Using the wrong filename or omitting quotes
5fill in blank
hard

Fill all three blanks to create a blueprint with a static folder, register it with a URL prefix, and generate a static file URL.

Flask
from flask import Flask, Blueprint, url_for

bp = Blueprint('files', __name__, static_folder=[1])
app = Flask(__name__)
app.register_blueprint(bp, url_prefix=[2])

static_url = url_for('[3].static', filename='image.png')
Drag options to blanks, or click blank then click option'
A'static'
B'/files'
Cfiles
D'/static'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up static folder name and URL prefix
Using incorrect blueprint name in url_for
Omitting quotes around strings