0
0
Djangoframework~20 mins

Template filters (date, length, default) in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Template Filters Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the output of this Django template snippet?
Given the context variable my_date with value 2024-06-15, what will this template output?

{{ my_date|date:"Y-m-d" }}
AJune 15, 2024
B06/15/2024
C15-06-2024
D2024-06-15
Attempts:
2 left
💡 Hint
The date filter formats the date according to the given string pattern.
state_output
intermediate
1:30remaining
What is the length output of this list in a Django template?
Given the context variable items as ["apple", "banana", "cherry"], what does this template output?

{{ items|length }}
A5
B3
C0
DError
Attempts:
2 left
💡 Hint
The length filter counts the number of items in a list.
📝 Syntax
advanced
2:00remaining
Which template filter usage correctly provides a default value?
You want to display the variable username but show 'Guest' if it is empty or undefined. Which option does this correctly?
A{{ username|default_guest }}
B{{ username|default_if_none:"Guest" }}
C{{ username|default:"Guest" }}
D{{ username|default('Guest') }}
Attempts:
2 left
💡 Hint
The default filter replaces empty or undefined variables with the given string.
🔧 Debug
advanced
2:00remaining
Why does this template raise an error?
Template snippet:
{{ my_date|date:Y-m-d }}

Assuming my_date is a valid date object, why does this cause an error?
AMissing quotes around the date format string causes a syntax error
Bmy_date is not a date object
CThe date filter does not accept format strings
DThe pipe symbol is invalid here
Attempts:
2 left
💡 Hint
Check how the date format string is passed to the filter.
🧠 Conceptual
expert
2:30remaining
What is the output of this Django template code?
Given the context variable user_name with value None, what does this template output?

{{ user_name|default:"Anonymous"|length }}
A9
B0
CError
DNone
Attempts:
2 left
💡 Hint
The default filter replaces None with 'Anonymous', then length counts characters.