Challenge - 5 Problems
Blueprint Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output when accessing a Blueprint route?
Given this Flask Blueprint setup, what will the browser display when visiting
/blog/?Flask
from flask import Blueprint, render_template_string blog = Blueprint('blog', __name__, template_folder='templates') @blog.route('/') def index(): return render_template_string('<h1>Blog Home</h1>') # Assume app.register_blueprint(blog, url_prefix='/blog') is done
Attempts:
2 left
💡 Hint
Think about how Blueprint routes are registered with a URL prefix.
✗ Incorrect
The Blueprint 'blog' is registered with the prefix '/blog'. The route '/' inside the Blueprint corresponds to '/blog/' in the app. The function returns a simple HTML heading, so the browser shows '
Blog Home
'.📝 Syntax
intermediate2:00remaining
Identify the syntax error in Blueprint route definition
Which option contains a syntax error in defining a Flask Blueprint route?
Flask
from flask import Blueprint api = Blueprint('api', __name__) @api.route('/data') def get_data(): return 'Data response'
Attempts:
2 left
💡 Hint
Check for missing colons and indentation.
✗ Incorrect
Option A is missing a colon after the function definition, causing a SyntaxError. Options A, C, and D are identical and correct.
❓ state_output
advanced2:00remaining
What template is rendered by this Blueprint route?
Given this Blueprint and template setup, what will be rendered when visiting
/shop/?Flask
from flask import Blueprint, render_template shop = Blueprint('shop', __name__, template_folder='shop_templates') @shop.route('/') def home(): return render_template('home.html') # Assume app.register_blueprint(shop, url_prefix='/shop') # Content of shop_templates/home.html: # <h2>Welcome to the Shop</h2>
Attempts:
2 left
💡 Hint
Check the template folder specified in the Blueprint and the template file name.
✗ Incorrect
The Blueprint specifies 'shop_templates' as its template folder. The route renders 'home.html' from that folder, which contains '
Welcome to the Shop
'. So this HTML is rendered.🔧 Debug
advanced2:00remaining
Why does this Blueprint route cause a 404 error?
Consider this Blueprint code and registration. Why does visiting
/admin/dashboard return 404?Flask
from flask import Blueprint admin = Blueprint('admin', __name__) @admin.route('/dashboard') def dashboard(): return 'Admin Dashboard' # In main app: # app.register_blueprint(admin, url_prefix='/admin/')
Attempts:
2 left
💡 Hint
Check how url_prefix with trailing slash affects route matching.
✗ Incorrect
Using url_prefix='/admin/' adds a trailing slash to the prefix. Flask concatenates this with the route '/dashboard' resulting in '/admin//dashboard' which does not match '/admin/dashboard'. This causes a 404 error. Removing the trailing slash in url_prefix fixes the issue.
🧠 Conceptual
expert3:00remaining
How does Flask resolve templates in nested Blueprints?
If you have a Blueprint 'store' with template_folder='templates/store' and inside it a nested Blueprint 'products' with template_folder='templates/store/products', which template path will Flask look for when rendering
render_template('list.html') inside 'products' Blueprint?Attempts:
2 left
💡 Hint
Blueprints use their own template_folder as base for render_template calls inside them.
✗ Incorrect
Each Blueprint uses its own template_folder as the root for templates. The nested 'products' Blueprint has template_folder='templates/store/products', so render_template('list.html') looks inside that folder. It does not fallback to parent Blueprint folders automatically.