0
0
Flaskframework~5 mins

Blueprint URL prefixes in Flask - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Blueprint in Flask?
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
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
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
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
Why is it important to avoid route name conflicts inside Blueprints sharing the same url_prefix?
ABecause Flask merges routes and conflicts cause errors
BBecause url_prefix changes route names automatically
CBecause Blueprints cannot share url_prefix
DBecause route names are ignored
Explain how URL prefixes work with Flask Blueprints and why they are useful.
Think about how you group pages under sections in a website.
You got /4 concepts.
    Describe the steps to register a Blueprint with a URL prefix in a Flask app.
    Focus on how you connect the Blueprint to the main app.
    You got /4 concepts.