0
0
Flaskframework~10 mins

Why template engines matter in Flask - Test Your Understanding

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

Complete the code to render a template in Flask.

Flask
from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def home():
    return [1]('index.html')
Drag options to blanks, or click blank then click option'
Arender_html
Brender_page
Crender_template
Drender_view
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function like render_html.
Trying to return the template file name as a string.
2fill in blank
medium

Complete the code to pass a variable to the template.

Flask
from flask import Flask, render_template
app = Flask(__name__)

@app.route('/user/<name>')
def user(name):
    return render_template('user.html', [1]=name)
Drag options to blanks, or click blank then click option'
Aname
Busername
Cuser_name
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name that doesn't match the template.
Forgetting to pass the variable at all.
3fill in blank
hard

Fix the error in the template syntax to display a variable.

Flask
<h1>Hello, [1]!</h1>
Drag options to blanks, or click blank then click option'
A[[ name ]]
B{% name %}
C{# name #}
D{{ name }}
Attempts:
3 left
💡 Hint
Common Mistakes
Using {% %} which is for logic, not variables.
Using incorrect brackets like [[ ]].
4fill in blank
hard

Fill both blanks to create a dictionary in a template that filters items with quantity greater than 5.

Flask
{% set filtered = {item: qty for item, qty in inventory.items() if qty [1] 5} %}
<ul>
  {% for item, qty in filtered.items() %}
    <li>[2]: {{qty}}</li>
  {% endfor %}
</ul>
Drag options to blanks, or click blank then click option'
A>
Bitem
Cquantity
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the filter.
Using 'quantity' which is not the key variable name.
5fill in blank
hard

Fill all three blanks to loop over a list of users and display their names in uppercase.

Flask
{% for [1] in [2] %}
  <p>{{ [3].upper() }}</p>
{% endfor %}
Drag options to blanks, or click blank then click option'
Auser
Busers
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'username' which is not defined.
Mixing variable names between loop and list.