Challenge - 5 Problems
Static Files Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Django template snippet?
Given the following Django template code, what will be the rendered HTML output assuming
STATIC_URL = '/static/' and the static file css/style.css exists?{% load static %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">Django
{% load static %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">Attempts:
2 left
💡 Hint
Remember that {% static %} prepends the STATIC_URL setting to the file path.
✗ Incorrect
The {% static %} tag generates the full URL by combining STATIC_URL and the given path. Since STATIC_URL is '/static/', the output is '/static/css/style.css'.
📝 Syntax
intermediate2:00remaining
Which option correctly loads and uses a static image in a Django template?
Select the Django template code snippet that correctly loads the static tag and displays an image located at
images/logo.png.Attempts:
2 left
💡 Hint
You must load the static template tag library before using {% static %}.
✗ Incorrect
Option D correctly loads the static tag library and uses the {% static %} tag with quotes around the path. Option D misses loading the tag library. Option D uses an outdated tag library and wrong syntax. Option D uses wrong syntax for the static tag.
🔧 Debug
advanced2:00remaining
Why does this Django template raise a TemplateSyntaxError?
Consider this Django template snippet:
Why does it raise a TemplateSyntaxError?
{% load static %}
<img src="{% static images/logo.png %}" alt="Logo">Why does it raise a TemplateSyntaxError?
Django
{% load static %}
<img src="{% static images/logo.png %}" alt="Logo">Attempts:
2 left
💡 Hint
Check how the path argument is passed to the static tag.
✗ Incorrect
The static tag requires its argument to be a quoted string. Omitting quotes causes a TemplateSyntaxError.
❓ state_output
advanced2:00remaining
What is the value of the rendered src attribute in this Django template?
Given
STATIC_URL = '/assets/' in settings.py, what will be the value of the src attribute after rendering this template?{% load static %}
<img src="{% static 'img/photo.jpg' %}" alt="Photo">Django
{% load static %}
<img src="{% static 'img/photo.jpg' %}" alt="Photo">Attempts:
2 left
💡 Hint
The static tag uses the STATIC_URL setting as prefix.
✗ Incorrect
Since STATIC_URL is set to '/assets/', the static tag outputs '/assets/img/photo.jpg'.
🧠 Conceptual
expert2:00remaining
Which statement about Django static files in templates is TRUE?
Choose the correct statement about using static files in Django templates.
Attempts:
2 left
💡 Hint
Think about how Django manages static files and the role of the static template tag.
✗ Incorrect
Option A correctly describes that {% static %} requires loading the static tag library and uses STATIC_URL to build URLs. Other options are incorrect because Django does not resolve static URLs automatically without the tag, does not require full URLs, and static files should be in static directories, not templates.