Challenge - 5 Problems
Template Variable 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 Django template snippet?
Given the context
{'user': {'name': 'Alice', 'age': 30}}, what will this template output?{% raw %}Hello, {{ user.name }}! You are {{ user.age }} years old.{% endraw %}Attempts:
2 left
💡 Hint
Remember that double braces {{ }} output the value of the variable from the context.
✗ Incorrect
The double braces {{ user.name }} and {{ user.age }} are replaced by the values from the context dictionary. So 'Alice' and '30' appear in the output.
📝 Syntax
intermediate1:30remaining
Which option correctly outputs the value of a variable in a Django template?
You want to display the value of the variable
title in your Django template. Which syntax is correct?Attempts:
2 left
💡 Hint
Variables in Django templates are enclosed in double curly braces.
✗ Incorrect
In Django templates, variables are displayed using double curly braces like {{ title }}. Other options are either template tags, comments, or invalid syntax.
🔧 Debug
advanced2:00remaining
What error occurs when using undefined variable in double braces?
Consider this template snippet:
Given the context
{% raw %}Hello, {{ user.full_name }}!{% endraw %}Given the context
{'user': {}}, what happens when rendering?Attempts:
2 left
💡 Hint
Django templates silently ignore missing variables by default.
✗ Incorrect
If a variable or attribute is missing in the context, Django outputs an empty string instead of raising an error.
🧠 Conceptual
advanced2:00remaining
How does Django template handle nested dictionary variables with double braces?
Given context
{'product': {'name': 'Book', 'price': 12.99}}, what does this template output?{% raw %}Product: {{ product.name }}, Price: ${{ product.price }}{% endraw %}Attempts:
2 left
💡 Hint
Double braces access nested dictionary keys using dot notation.
✗ Incorrect
Django templates allow accessing nested dictionary keys with dot notation inside double braces, so the values are replaced correctly.
❓ state_output
expert2:30remaining
What is the output when using a filter with double braces in Django template?
Given context
{'name': 'alice'}, what is the output of this template?{% raw %}Hello, {{ name|capfirst }}!{% endraw %}Attempts:
2 left
💡 Hint
The capfirst filter capitalizes the first letter of the string.
✗ Incorrect
The capfirst filter changes the first character to uppercase, so 'alice' becomes 'Alice'.