A Blueprint in Flask is a way to organize a group of related routes and functions. It helps split a large app into smaller parts, like chapters in a book.
Click to reveal answer
beginner
What does the URL prefix do when registering a Blueprint?
The URL prefix adds a starting path to all routes inside the Blueprint. For example, if the prefix is '/admin', all Blueprint routes start with '/admin'.
Click to reveal answer
beginner
How do you register a Blueprint with a URL prefix in Flask?
Use app.register_blueprint(blueprint, url_prefix='/prefix'). This tells Flask to add '/prefix' before all Blueprint routes.
Click to reveal answer
intermediate
Why use URL prefixes with Blueprints?
URL prefixes help group routes logically and avoid conflicts. For example, '/user' prefix for user pages and '/admin' for admin pages.
Click to reveal answer
intermediate
What happens if you register two Blueprints with the same URL prefix?
Flask will combine their routes under the same prefix. If routes inside conflict, Flask raises an error. So, route paths inside Blueprints should be unique.
Click to reveal answer
What is the purpose of the url_prefix parameter when registering a Blueprint?
ATo add a common path before all Blueprint routes
BTo change the Blueprint's name
CTo disable the Blueprint routes
DTo set the Blueprint's template folder
✗ Incorrect
The url_prefix adds a common path before all routes in the Blueprint, grouping them under that prefix.
If a Blueprint has a route '/dashboard' and is registered with url_prefix='/admin', what is the full URL path?
A/dashboard
B/admin
C/dashboard/admin
D/admin/dashboard
✗ Incorrect
The url_prefix '/admin' is added before the Blueprint route '/dashboard', making the full path '/admin/dashboard'.
Can you register multiple Blueprints with different url_prefix values in the same Flask app?
ANo, only one Blueprint per app
BYes, each can have its own url_prefix
CYes, but all must share the same url_prefix
DNo, url_prefix is not allowed
✗ Incorrect
You can register many Blueprints, each with its own url_prefix to organize routes.
What happens if you register a Blueprint without specifying url_prefix?
ABlueprint routes are not accessible
BFlask throws an error
CBlueprint routes are registered at the root level
DBlueprint routes get a default prefix
✗ Incorrect
Without url_prefix, Blueprint routes are registered directly at the root URL level.
Why is it important to avoid route name conflicts inside Blueprints sharing the same url_prefix?
ABecause Flask merges routes and conflicts cause errors