0
0
Djangoframework~10 mins

Template filters (date, length, default) in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to format the date using the Django template date filter.

Django
{{ post.published_date|[1] }}
Drag options to blanks, or click blank then click option'
Adefault:"N/A"
Blength
Cdate:"Y-m-d"
Dupper
Attempts:
3 left
💡 Hint
Common Mistakes
Using the length filter instead of date.
Forgetting to include the format string in quotes.
2fill in blank
medium

Complete the code to get the length of the list using the Django template length filter.

Django
{{ user.friends|[1] }}
Drag options to blanks, or click blank then click option'
Alength
Bdate:"Y"
Cdefault:"0"
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using date filter on a list.
Using default filter instead of length.
3fill in blank
hard

Fix the error in the code to provide a default value if the variable is empty.

Django
{{ user.nickname|[1] }}
Drag options to blanks, or click blank then click option'
Aupper
Blength
Cdate:"d M Y"
Ddefault:"Anonymous"
Attempts:
3 left
💡 Hint
Common Mistakes
Using length filter instead of default.
Not including quotes around the default value.
4fill in blank
hard

Fill both blanks to format the date and provide a default if the date is missing.

Django
{{ event.start_date|[1]|[2] }}
Drag options to blanks, or click blank then click option'
Adate:"M d, Y"
Bdefault:"Date not set"
Clength
Dupper
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of filters.
Using length filter instead of default.
5fill in blank
hard

Fill all three blanks to get the length of a list, provide a default if empty, and convert the result to a string.

Django
{{ items|[1]|[2]|[3] }}
Drag options to blanks, or click blank then click option'
Alength
Bdefault:"0"
Cstringformat:"%s"
Ddate:"Y"
Attempts:
3 left
💡 Hint
Common Mistakes
Using date filter instead of stringformat.
Not chaining filters in correct order.