Given a Flask blueprint with a URL prefix, what URL will respond to the hello route?
from flask import Flask, Blueprint bp = Blueprint('bp', __name__, url_prefix='/api') @bp.route('/hello') def hello(): return 'Hello from blueprint!' app = Flask(__name__) app.register_blueprint(bp)
Remember the url_prefix adds a prefix to all routes in the blueprint.
The blueprint has url_prefix='/api', so the route /hello becomes /api/hello when registered.
Consider this Flask blueprint with a URL prefix. What response will the client get when accessing /dashboard/?
from flask import Flask, Blueprint dashboard = Blueprint('dashboard', __name__, url_prefix='/dashboard') @dashboard.route('/') def index(): return 'Dashboard Home' app = Flask(__name__) app.register_blueprint(dashboard)
The route is defined at / inside the blueprint with prefix /dashboard.
Accessing /dashboard/ matches the blueprint's / route, returning 'Dashboard Home'.
Choose the code snippet that correctly creates a Flask blueprint with URL prefix /shop and a route /items that returns 'Shop Items'.
URL prefixes and routes must start with a slash / to be valid.
Option A correctly sets url_prefix='/shop' and route /items. Options C and D miss the leading slash in route or prefix. Option A does not use url_prefix.
Given this Flask app and blueprint, why does accessing /blog/post return 404?
from flask import Flask, Blueprint blog = Blueprint('blog', __name__, url_prefix='/blog') @blog.route('post') def post(): return 'Blog Post' app = Flask(__name__) app.register_blueprint(blog)
Check the route string in the decorator for correct syntax.
Flask requires route paths to start with a slash. Missing it causes the route not to register properly, leading to 404.
Suppose you register two blueprints with the same URL prefix /api. How does Flask handle routing when both define a route /status?
Think about how Flask registers routes internally and what happens if two routes have the same URL.
Flask does not raise an error but the last registered route for a URL overrides any previous one, so only one function handles requests to that URL.