0
0
Flaskframework~5 mins

Blueprint routes and templates 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 templates. It helps split a large app into smaller parts, like chapters in a book, making the app easier to manage.
Click to reveal answer
beginner
How do you register a Blueprint in a Flask app?
You create a Blueprint object, define routes on it, then register it on the main Flask app using app.register_blueprint(blueprint). This connects the Blueprint's routes to the app.
Click to reveal answer
intermediate
How do Blueprints help with templates in Flask?
Blueprints can have their own templates folder. When rendering templates inside a Blueprint, Flask looks in that folder first, keeping templates organized by feature or section.
Click to reveal answer
intermediate
What is the purpose of the 'url_prefix' parameter when registering a Blueprint?
The 'url_prefix' adds a common path before all routes in the Blueprint. For example, if url_prefix='/blog', all routes in that Blueprint start with '/blog', like '/blog/post1'.
Click to reveal answer
intermediate
Can Blueprints be used to share static files in Flask?
Yes, Blueprints can have their own static folder. This lets you organize static files like images or CSS by feature, and Flask serves them under the Blueprint's static path.
Click to reveal answer
What is the main benefit of using Blueprints in Flask?
AMake the app run faster
BOrganize routes and templates into reusable parts
CAutomatically create database tables
DReplace the Flask app object
How do you tell Flask to use a Blueprint's routes?
ABy setting a config variable
BBy importing the Blueprint only
CBy calling app.register_blueprint(blueprint)
DBy adding routes to app directly
If a Blueprint has url_prefix='/shop', what URL will the route @bp.route('/cart') respond to?
A/cart
B/shop
C/cart/shop
D/shop/cart
Where does Flask look for templates when rendering inside a Blueprint?
AIn the Blueprint's templates folder first
BOnly in the main app's templates folder
CIn the static folder
DIn the root directory
Can Blueprints have their own static files?
AYes, Blueprints can have a static folder
BNo, static files must be in the main app
COnly if you use a plugin
DStatic files are not supported in Blueprints
Explain how Blueprints help organize routes and templates in a Flask app.
Think of Blueprints like chapters in a book.
You got /4 concepts.
    Describe the role of the url_prefix parameter when registering a Blueprint.
    It’s like a folder name for URLs.
    You got /3 concepts.