0
0
Flaskframework~10 mins

Blueprint routes and templates in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to register a blueprint named 'blog' in a Flask app.

Flask
from flask import Flask, Blueprint

blog = Blueprint('blog', __name__)

app = Flask(__name__)
app.[1](blog)
Drag options to blanks, or click blank then click option'
Aregister_blueprint
Badd_blueprint
Cinclude_blueprint
Dattach_blueprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like add_blueprint or include_blueprint which do not exist.
2fill in blank
medium

Complete the route decorator to define a route '/post' inside the 'blog' blueprint.

Flask
from flask import Blueprint

blog = Blueprint('blog', __name__)

@blog.[1]('/post')
def show_post():
    return 'Post page'
Drag options to blanks, or click blank then click option'
Aregister
Burl_for
Cendpoint
Droute
Attempts:
3 left
💡 Hint
Common Mistakes
Using url_for or endpoint as decorators which are not route decorators.
3fill in blank
hard

Fix the error in the blueprint template rendering code to render 'post.html'.

Flask
from flask import Blueprint, render_template

blog = Blueprint('blog', __name__, template_folder='templates')

@blog.route('/post')
def show_post():
    return [1]('post.html')
Drag options to blanks, or click blank then click option'
Arender_template
Brender
Crender_html
Dtemplate_render
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like render or render_html.
4fill in blank
hard

Fill both blanks to create a blueprint named 'shop' with a URL prefix '/store'.

Flask
from flask import Blueprint

shop = Blueprint('[1]', __name__, url_prefix='[2]')
Drag options to blanks, or click blank then click option'
Ashop
Bstore
C/shop
D/store
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash in the URL prefix or mixing names.
5fill in blank
hard

Fill all three blanks to create a route '/item/' in the 'shop' blueprint that renders 'item.html' passing the id.

Flask
from flask import Blueprint, render_template

shop = Blueprint('shop', __name__)

@shop.[1]('/item/<int:id>')
def show_item([2]):
    return [3]('item.html', id=id)
Drag options to blanks, or click blank then click option'
Aroute
Bid
Crender_template
Durl_for
Attempts:
3 left
💡 Hint
Common Mistakes
Using url_for instead of render_template, or wrong parameter names.