0
0
Flaskframework~10 mins

Template filters 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 apply the 'upper' filter in a Flask template.

Flask
{{ '{{ name[1]' }} }}
Drag options to blanks, or click blank then click option'
A|upper
B|lower
C|title
D|capitalize
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong filter name like 'lower' or 'title' instead of 'upper'.
Forgetting the pipe symbol before the filter.
2fill in blank
medium

Complete the code to format a number with two decimal places using the 'format' filter.

Flask
{{ '{{ price[1]' }} }}
Drag options to blanks, or click blank then click option'
A|format('%.3f')
B|format('%.2f')
C|format('%.1f')
D|format('%.0f')
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong number of decimal places in the format string.
Forgetting to include the format string inside parentheses and quotes.
3fill in blank
hard

Fix the error in the code to safely display HTML content using the 'safe' filter.

Flask
{{ '{{ content[1]' }} }}
Drag options to blanks, or click blank then click option'
A|safe
B|striptags
C|escape
D|replace('<', '&lt;')
Attempts:
3 left
💡 Hint
Common Mistakes
Using escape which does the opposite by escaping HTML.
Not using any filter and expecting HTML to render.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension in a Flask template that filters items with value greater than 10.

Flask
{% raw %}{% set filtered = {key: value for key, value in items.items() if value [1] 10} %}{% endraw %}
Drag options to blanks, or click blank then click option'
A!=
B<
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using < or == which filter different values.
Forgetting to use a comparison operator.
5fill in blank
hard

Fill all three blanks to create a Flask template expression that converts a string to lowercase, then replaces spaces with dashes, and finally trims whitespace.

Flask
{{ '{{ text[1][2][3]' }} }}
Drag options to blanks, or click blank then click option'
A|lower
B|replace(' ', '-')
C|trim
D|upper
Attempts:
3 left
💡 Hint
Common Mistakes
Using upper instead of lower.
Not chaining filters in the correct order.
Forgetting to include quotes inside the replace filter.