0
0
Flaskframework~10 mins

Variable substitution syntax 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 display a variable in a Flask template using Jinja2 syntax.

Flask
<p>Hello, {{ [1] }}!</p>
Drag options to blanks, or click blank then click option'
Aname
Bvar
Cinput
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using Python functions like print inside {{ }}
Forgetting to use double curly braces
Using incorrect variable names
2fill in blank
medium

Complete the code to substitute a variable called 'user' in the template.

Flask
<h1>Welcome, {{ [1] }}!</h1>
Drag options to blanks, or click blank then click option'
Auser
Bname
Cusername
Dvisitor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than passed
Missing the double curly braces
Using single curly braces
3fill in blank
hard

Fix the error in the template variable substitution syntax.

Flask
<p>Your score is {{ [1] }}</p>
Drag options to blanks, or click blank then click option'
Ascore;
Bscore()
Cscore:
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses like function calls
Adding semicolons or colons
Using incorrect variable names
4fill in blank
hard

Fill both blanks to correctly display a user's first and last name using variable substitution.

Flask
<p>Full name: {{ [1] }} {{ [2] }}</p>
Drag options to blanks, or click blank then click option'
Afirst_name
Blast_name
Cusername
Dfullname
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single variable for full name when separate variables exist
Forgetting to use double curly braces for both variables
Mixing variable names
5fill in blank
hard

Fill all three blanks to create a dictionary in a Jinja2 template showing item names and their prices if price is greater than 10.

Flask
{% set expensive_items = { [1]: [2] for [3] in items if [2] > 10 } %}
Drag options to blanks, or click blank then click option'
Aitem.name
Bitem.price
Citem
Ditems
Attempts:
3 left
💡 Hint
Common Mistakes
Using the list name as loop variable
Mixing keys and values
Incorrect comparison syntax