Bird
Raised Fist0
Flaskframework~20 mins

Blueprint routes and templates in Flask - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Blueprint Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2: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
A404 Not Found error
B<h1>Blog Home</h1>
C500 Internal Server Error
DEmpty page with status 200
Attempts:
2 left
💡 Hint
Think about how Blueprint routes are registered with a URL prefix.
📝 Syntax
intermediate
2: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'
A
@api.route('/data')
def get_data()
    return 'Data response'
B
@api.route('/data')
def get_data():
    return 'Data response'
C
'esnopser ataD' nruter    
:)(atad_teg fed
)'atad/'(etuor.ipa@
D
api.route('/data')
def get_data():
    return 'Data response'
Attempts:
2 left
💡 Hint
Check for missing colons and indentation.
❓ state_output
advanced
2: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>
A<h2>Welcome to the Shop</h2>
B<h1>Shop Home</h1>
CTemplateNotFound error
DEmpty response with status 200
Attempts:
2 left
💡 Hint
Check the template folder specified in the Blueprint and the template file name.
🔧 Debug
advanced
2: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/')
AThe function 'dashboard' is missing a return statement.
BThe route '/dashboard' inside Blueprint is incorrect syntax.
CThe url_prefix has a trailing slash causing route mismatch.
DBlueprint name 'admin' conflicts with Flask reserved keywords.
Attempts:
2 left
💡 Hint
Check how url_prefix with trailing slash affects route matching.
🧠 Conceptual
expert
3: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?
Atemplates/list.html
Btemplates/store/products/templates/list.html
Ctemplates/store/list.html
Dtemplates/store/products/list.html
Attempts:
2 left
💡 Hint
Blueprints use their own template_folder as base for render_template calls inside them.

Practice

(1/5)
1. What is the main purpose of using a Blueprint in a Flask application?
easy
A. To handle user authentication automatically
B. To organize routes and templates into reusable components
C. To create a new Flask app instance
D. To connect Flask with a database

Solution

  1. Step 1: Understand Blueprint role

    A Blueprint groups related routes and templates to keep code organized.
  2. Step 2: Compare other options

    Connecting to databases, creating app instances, or handling authentication are separate tasks.
  3. Final Answer:

    To organize routes and templates into reusable components -> Option B
  4. Quick Check:

    Blueprint = organize routes/templates [OK]
Hint: Blueprints group routes/templates for better app structure [OK]
Common Mistakes:
  • Thinking Blueprint creates the app instance
  • Confusing Blueprint with database connection
  • Assuming Blueprint handles authentication automatically
2. Which of the following is the correct way to register a Blueprint named blog with a Flask app app using the URL prefix /blog?
easy
A. app.register_blueprint(blog, url_prefix='/blog')
B. app.register_blueprint('/blog', blog)
C. app.register_blueprint(blog.prefix('/blog'))
D. app.register_blueprint(blog, prefix_url='/blog')

Solution

  1. Step 1: Recall correct method signature

    The method is register_blueprint(blueprint, url_prefix='...').
  2. Step 2: Check options for correct syntax

    Only app.register_blueprint(blog, url_prefix='/blog') uses the correct method and parameter names.
  3. Final Answer:

    app.register_blueprint(blog, url_prefix='/blog') -> Option A
  4. Quick Check:

    register_blueprint with url_prefix = app.register_blueprint(blog, url_prefix='/blog') [OK]
Hint: Use url_prefix parameter to set Blueprint URL base [OK]
Common Mistakes:
  • Swapping parameter order
  • Using wrong parameter name like prefix_url
  • Calling prefix as a method on Blueprint
3. Given this Blueprint code:
from flask import Blueprint, render_template
blog = Blueprint('blog', __name__, template_folder='templates')

@blog.route('/post')
def show_post():
    return render_template('post.html')

And this main app code:
from flask import Flask
app = Flask(__name__)
app.register_blueprint(blog, url_prefix='/blog')

What URL should you visit to see the post.html template rendered?
medium
A. /blog
B. /post
C. /blog/post
D. /post/blog

Solution

  1. Step 1: Understand route and url_prefix

    The Blueprint route is '/post', and the Blueprint is registered with prefix '/blog'.
  2. Step 2: Combine prefix and route

    The full URL becomes '/blog/post' to access the route.
  3. Final Answer:

    /blog/post -> Option C
  4. Quick Check:

    url_prefix + route = /blog/post [OK]
Hint: Combine url_prefix and route for full URL [OK]
Common Mistakes:
  • Ignoring url_prefix and using only route
  • Swapping url_prefix and route order
  • Assuming url_prefix is not added to route
4. What is wrong with this Blueprint registration code?
from flask import Flask
app = Flask(__name__)
app.register_blueprint(blog, prefix='/blog')
medium
A. You cannot register blueprints in Flask
B. Blueprint must be registered before app creation
C. Blueprint name must be 'app' to register
D. The parameter should be url_prefix, not prefix

Solution

  1. Step 1: Check parameter name in register_blueprint

    The correct parameter to set URL prefix is url_prefix, not prefix.
  2. Step 2: Validate other options

    Blueprints register after app creation; name can be anything; Flask supports blueprints.
  3. Final Answer:

    The parameter should be url_prefix, not prefix -> Option D
  4. Quick Check:

    Correct param is url_prefix [OK]
Hint: Use url_prefix, not prefix, when registering Blueprint [OK]
Common Mistakes:
  • Using prefix instead of url_prefix
  • Trying to register Blueprint before app exists
  • Thinking Blueprint name must be 'app'
5. You have two Blueprints, admin and user, both with a route /dashboard. How can you register them in your Flask app to avoid URL conflicts and keep URLs clear?
hard
A. Register each Blueprint with a different url_prefix, like /admin and /user
B. Rename one Blueprint's route to /dashboard2
C. Register both Blueprints without any url_prefix
D. Use the same url_prefix for both Blueprints

Solution

  1. Step 1: Understand URL conflicts

    Both Blueprints have the same route /dashboard, which causes conflicts if no prefix is used.
  2. Step 2: Use url_prefix to separate routes

    Assigning different url_prefix values like /admin and /user keeps URLs unique and organized.
  3. Final Answer:

    Register each Blueprint with a different url_prefix, like /admin and /user -> Option A
  4. Quick Check:

    Different url_prefix avoids route conflicts [OK]
Hint: Use unique url_prefix for each Blueprint to avoid conflicts [OK]
Common Mistakes:
  • Not using url_prefix and causing route clashes
  • Renaming routes manually instead of using prefixes
  • Using same url_prefix for multiple Blueprints
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard