Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load the static tag library in Django.
Django
{% load [1] %} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'url' instead of 'static' to load static files.
Trying to load 'template' which is not a valid tag.
✗ Incorrect
The {% load static %} tag provides support for static files in Django templates.
2fill in blank
mediumComplete the code to display a variable named 'title' in a Django template.
Django
<h1>{{ [1] }}</h1> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not passed from the view.
Forgetting the double curly braces.
✗ Incorrect
Using {{ title }} displays the value of the 'title' variable in the template.
3fill in blank
hardFix the error in the template tag to include another template named 'header.html'.
Django
{% [1] 'header.html' %} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'load' which is for loading tags, not templates.
Using 'extends' which is for template inheritance.
✗ Incorrect
The {% include 'header.html' %} tag inserts the content of 'header.html' here.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
Django
{ [1]: len([2]) for [2] in words if len([2]) > 3 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'words' as the key instead of the loop variable.
Using 'len' as the loop variable.
✗ Incorrect
The comprehension uses 'word' as key and len(word) as value for words longer than 3 letters.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps uppercase keys to their values only if value is positive.
Django
result = { [1].upper(): [2] for [1], [2] in data.items() if [2] [3] 0 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'key.upper()' as loop variable.
Using wrong comparison operator.
✗ Incorrect
We loop over key, value in data.items(), use key.upper() as key, value as value, and filter values > 0.