Assuming default '/static/' prefix instead of custom '/assets/'
Mixing media URL with static URL
Ignoring STATIC_URL setting in templates
4. You added a static image file and referenced it in your template using {% static 'images/logo.png' %}, but the image does not show during development. Which is the most likely cause?
medium
A. You did not set MEDIA_URL correctly.
B. You forgot to run collectstatic during development.
C. The django.contrib.staticfiles app is not in INSTALLED_APPS.
D. The STATIC_URL setting is missing a trailing slash.
Solution
Step 1: Check staticfiles app presence
Django serves static files in development only if 'django.contrib.staticfiles' is in INSTALLED_APPS.
Step 2: Understand collectstatic role
collectstatic is for production; during development, staticfiles app handles serving automatically.
Final Answer:
The django.contrib.staticfiles app is not in INSTALLED_APPS. -> Option C
Hint: Ensure 'django.contrib.staticfiles' is in INSTALLED_APPS [OK]
Common Mistakes:
Running collectstatic unnecessarily in development
Confusing MEDIA_URL with STATIC_URL
Ignoring INSTALLED_APPS configuration
5. You want to serve static files from a custom folder named assets inside your Django app during development. Which combination of settings and template usage will correctly serve a CSS file assets/css/style.css?
Choose the correct settings and template snippet.
hard
A. In settings.py: STATICFILES_DIRS = [BASE_DIR / 'assets'] In template: <link href="{% static 'css/style.css' %}" rel="stylesheet">
B. In settings.py: MEDIA_URL = '/assets/' In template: <link href="{% static 'css/style.css' %}" rel="stylesheet">
C. In settings.py: STATIC_ROOT = 'assets' In template: <link href="/assets/css/style.css" rel="stylesheet">
D. In settings.py: STATICFILES_DIRS = ['assets'] In template: <link href="{% static 'css/style.css' %}" rel="stylesheet">
Solution
Step 1: Configure STATICFILES_DIRS correctly
STATICFILES_DIRS should be a list of absolute paths; using BASE_DIR / 'assets' ensures correct path to the assets folder.
Step 2: Use {% static %} tag with relative path
The template should use {% static 'css/style.css' %} to generate the URL, matching the folder structure inside assets.
Final Answer:
In settings.py: STATICFILES_DIRS = [BASE_DIR / 'assets'] and in template: <link href="{% static 'css/style.css' %}" rel="stylesheet"> -> Option A
Quick Check:
STATICFILES_DIRS needs absolute path; use {% static %} for URLs [OK]
Hint: Use absolute path in STATICFILES_DIRS and {% static %} tag [OK]
Common Mistakes:
Using relative path strings without BASE_DIR
Confusing STATIC_ROOT with STATICFILES_DIRS
Setting MEDIA_URL instead of STATICFILES_DIRS
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.