Recall & Review
beginner
What is the purpose of the
{% if %} statement in Flask templates?The
{% if %} statement is used to conditionally display parts of the HTML based on a condition. It helps show or hide content dynamically.Click to reveal answer
beginner
How do you loop over a list in a Flask template?
You use the
{% for item in list %} statement to repeat HTML for each item in the list. It helps display multiple items like a list or table rows.Click to reveal answer
beginner
What happens if the
{% if %} condition is false in a Flask template?The HTML inside the
{% if %} block is skipped and not shown. You can use {% else %} to show alternative content.Click to reveal answer
intermediate
Can you nest
{% for %} loops inside each other in Flask templates?Yes, you can nest
{% for %} loops to handle complex data like lists of lists. Just make sure to use different variable names to avoid confusion.Click to reveal answer
beginner
What is the syntax to end a control structure like
{% if %} or {% for %} in Flask templates?You close control structures with
{% endif %} for if and {% endfor %} for for loops.Click to reveal answer
Which tag starts a conditional block in a Flask template?
✗ Incorrect
The {% if %} tag starts a conditional block in Flask templates.
How do you end a for loop in a Flask template?
✗ Incorrect
You end a for loop with {% endfor %} in Flask templates.
What will happen if the condition in {% if %} is false and there is no {% else %}?
✗ Incorrect
If the condition is false and no else block exists, the content inside the if block is skipped.
Which of these is a correct way to loop over a list named 'items' in Flask template?
✗ Incorrect
The correct syntax is {% for item in items %}.
Can you use an if statement inside a for loop in Flask templates?
✗ Incorrect
You can nest if statements inside for loops to control what is shown for each item.
Explain how to use
{% if %} and {% for %} in a Flask template to show a list only if it has items.Think about showing content only when there is something to show.
You got /3 concepts.
Describe how nesting a for loop inside an if statement works in Flask templates.
Imagine checking a condition before listing items.
You got /4 concepts.