0
0
Flaskframework~20 mins

Blueprint static files in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Blueprint Static Files Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Flask serve static files from a Blueprint?

Consider a Flask Blueprint named admin with a static folder configured. When you access /admin/static/logo.png, what happens?

Flask
from flask import Blueprint
admin = Blueprint('admin', __name__, static_folder='static')
AFlask serves the file located at <code>admin/static/logo.png</code> inside the Blueprint folder.
BFlask serves the file from the main app's static folder ignoring the Blueprint's static folder.
CFlask raises a 404 error because static files cannot be served from Blueprints.
DFlask serves the file only if <code>static_url_path</code> is set explicitly in the Blueprint.
Attempts:
2 left
💡 Hint

Blueprints can have their own static folders served under a URL path.

📝 Syntax
intermediate
2:00remaining
Correct Blueprint static folder URL path syntax

Which option correctly sets a Blueprint named shop to serve static files under the URL path /shop-assets/?

Ashop = Blueprint('shop', __name__, static_folder='static', static_url_path='/shop/assets')
Bshop = Blueprint('shop', __name__, static_folder='static', static_url_path='/shop-assets')
Cshop = Blueprint('shop', __name__, static_folder='static', static_url_path='shop-assets')
Dshop = Blueprint('shop', __name__, static_folder='static', static_url_path='//shop-assets')
Attempts:
2 left
💡 Hint

The static_url_path must start with a slash to be a valid URL path.

🔧 Debug
advanced
2:00remaining
Why does Flask not serve Blueprint static files?

Given this Blueprint setup, static files are not served at /blog/static/. What is the likely cause?

blog = Blueprint('blog', __name__)

@app.route('/blog/static/')
def static_files(filename):
    return send_from_directory('static', filename)
ABlueprints cannot serve static files; static files must be served only by the main app.
BThe route <code>/blog/static/&lt;path:filename&gt;</code> conflicts with Flask's default static route causing a server error.
CThe Blueprint lacks <code>static_folder</code> configuration, so Flask does not serve static files automatically.
DThe <code>send_from_directory</code> function is used incorrectly and raises a TypeError.
Attempts:
2 left
💡 Hint

Blueprints serve static files automatically only if static_folder is set.

state_output
advanced
2:00remaining
What is the URL for a Blueprint static file with custom static_url_path?

A Blueprint api is created with static_folder='assets' and static_url_path='/api-static'. What URL serves the file logo.png inside assets?

Flask
api = Blueprint('api', __name__, static_folder='assets', static_url_path='/api-static')
A/api-static/logo.png
B/api/assets/logo.png
C/api/static/logo.png
D/static/api/logo.png
Attempts:
2 left
💡 Hint

The static_url_path defines the URL prefix for static files.

🧠 Conceptual
expert
3:00remaining
Why use Blueprint static files instead of main app static folder?

What is the main advantage of serving static files from a Flask Blueprint's static folder instead of the main app's static folder?

AIt enables serving static files only over HTTPS for security.
BIt improves server performance by caching static files separately per Blueprint.
CIt automatically compresses static files for faster delivery without extra configuration.
DIt allows modular organization so each Blueprint can manage its own static assets independently.
Attempts:
2 left
💡 Hint

Think about how Blueprints help organize code and resources.