0
0
Djangoframework~20 mins

Template variables with double braces in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Template Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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 %}
AHello, Alice! You are {{ user.age }} years old.
BHello, {{ user.name }}! You are {{ user.age }} years old.
CHello, user.name! You are user.age years old.
DHello, Alice! You are 30 years old.
Attempts:
2 left
💡 Hint
Remember that double braces {{ }} output the value of the variable from the context.
📝 Syntax
intermediate
1: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?
A{{ title }}
B{% title %}
C{# title #}
D[[ title ]]
Attempts:
2 left
💡 Hint
Variables in Django templates are enclosed in double curly braces.
🔧 Debug
advanced
2:00remaining
What error occurs when using undefined variable in double braces?
Consider this template snippet:

{% raw %}Hello, {{ user.full_name }}!{% endraw %}

Given the context {'user': {}}, what happens when rendering?
AOutputs: Hello, ! (empty string for missing variable)
BTemplateSyntaxError: 'full_name' is not defined
CRaises KeyError at runtime
DOutputs: Hello, {{ user.full_name }}!
Attempts:
2 left
💡 Hint
Django templates silently ignore missing variables by default.
🧠 Conceptual
advanced
2: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 %}
AProduct: {{ product.name }}, Price: ${{ product.price }}
BProduct: Book, Price: $12.99
CProduct: Book, Price: ${{ price }}
DProduct: product.name, Price: $product.price
Attempts:
2 left
💡 Hint
Double braces access nested dictionary keys using dot notation.
state_output
expert
2: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 %}
AHello, ALICE!
BHello, alice!
CHello, Alice!
DHello, {{ name|capfirst }}!
Attempts:
2 left
💡 Hint
The capfirst filter capitalizes the first letter of the string.