Challenge - 5 Problems
HTML Email Templates Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the rendered output of this Flask email template?
Given this Flask Jinja2 email template, what will be the rendered HTML output when
user_name='Alice' and items=['Book', 'Pen']?Flask
{% raw %}
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Order</title></head>
<body>
<h1>Hello {{ user_name }}!</h1>
<p>Your order includes:</p>
<ul>
{% for item in items %}
<li>{{ item }}</li>
{% endfor %}
</ul>
</body>
</html>
{% endraw %}Attempts:
2 left
💡 Hint
Remember how Jinja2 loops work to render each item in the list.
✗ Incorrect
The template loops over all items in the list and creates a for each. Since items=['Book', 'Pen'], both appear in the list.
📝 Syntax
intermediate2:00remaining
Which option causes a syntax error in this Flask email template?
Identify which option contains a syntax error in the Jinja2 template for an email body.
Flask
{% raw %}
<html>
<body>
<p>Dear {{ user }},</p>
{% if items %}
<ul>
{% for item in items %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% else %}
<p>No items ordered.</p>
{% endif %}
</body>
</html>
{% endraw %}Attempts:
2 left
💡 Hint
Check the closing tags for Jinja2 control structures carefully.
✗ Incorrect
Option C uses {% end %} which is not a valid Jinja2 tag. The correct closing tag is {% endif %}.
❓ state_output
advanced2:00remaining
What is the value of the variable
email_body after rendering?Given this Flask code snippet that renders an email template, what is the value of
email_body?Flask
from flask import render_template_string template = ''' <html> <body> <h2>Welcome {{ user }}!</h2> {% if discount %} <p>You have a {{ discount }}% discount.</p> {% else %} <p>No discounts available.</p> {% endif %} </body> </html> ''' email_body = render_template_string(template, user='Bob', discount=0)
Attempts:
2 left
💡 Hint
In Jinja2, 0 is treated as False in conditions. Check how the if statement evaluates.
✗ Incorrect
In Jinja2, 0 is considered False, so the else block runs. But since discount=0 is passed, the if block is false, so the else block content is rendered.
🔧 Debug
advanced2:00remaining
Why does this Flask email template render an empty list?
This Flask email template is supposed to list items, but the output shows an empty
- . What is the cause?
Flask
{% raw %}
<ul>
{% for item in items %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endraw %}
# Flask render call:
# render_template_string(template, items=None)Attempts:
2 left
💡 Hint
Check the value passed to 'items' and how Jinja2 handles None in loops.
✗ Incorrect
If 'items' is None, the for loop does not iterate, so no elements are created, resulting in an empty
- .
🧠 Conceptual
expert2:00remaining
Which option correctly explains why inline CSS is preferred in HTML email templates?
Why do most HTML email templates use inline CSS styles instead of external or embedded styles?
Attempts:
2 left
💡 Hint
Think about how email clients handle CSS for security and compatibility.
✗ Incorrect
Most email clients block or ignore