Consider a Flask Blueprint named admin with a static folder configured. When you access /admin/static/logo.png, what happens?
from flask import Blueprint admin = Blueprint('admin', __name__, static_folder='static')
Blueprints can have their own static folders served under a URL path.
Blueprints in Flask can have their own static folders. Flask automatically serves static files from the Blueprint's static_folder under the URL path /blueprint_name/static/.
Which option correctly sets a Blueprint named shop to serve static files under the URL path /shop-assets/?
The static_url_path must start with a slash to be a valid URL path.
The static_url_path parameter defines the URL prefix for static files. It must start with a slash to be valid. Option B correctly sets it to /shop-assets.
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) Blueprints serve static files automatically only if static_folder is set.
If a Blueprint does not specify static_folder, Flask does not serve static files for it automatically. The manual route shown does not replace this behavior.
A Blueprint api is created with static_folder='assets' and static_url_path='/api-static'. What URL serves the file logo.png inside assets?
api = Blueprint('api', __name__, static_folder='assets', static_url_path='/api-static')
The static_url_path defines the URL prefix for static files.
The static_url_path parameter sets the URL path prefix for the Blueprint's static files. So the file logo.png is served at /api-static/logo.png.
What is the main advantage of serving static files from a Flask Blueprint's static folder instead of the main app's static folder?
Think about how Blueprints help organize code and resources.
Blueprint static folders let each Blueprint keep its own static files. This keeps the project modular and easier to maintain, especially in large apps.