0
0
Djangoframework~20 mins

STATIC_URL and STATICFILES_DIRS in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Static Files Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of STATIC_URL in Django
What is the main purpose of the STATIC_URL setting in a Django project?
AIt defines the URL prefix used to serve static files in templates and browsers.
BIt lists all directories where Django looks for static files during development.
CIt specifies the absolute file system path where static files are collected.
DIt configures the database table used to store static file metadata.
Attempts:
2 left
💡 Hint
Think about how static files are referenced in HTML pages.
🧠 Conceptual
intermediate
1:30remaining
Role of STATICFILES_DIRS in Django
What does the STATICFILES_DIRS setting do in a Django project?
AIt defines the directory where static files are collected for production deployment.
BIt sets the URL path prefix for static files served by the web server.
CIt tells Django where to find additional static files during development besides app static folders.
DIt configures caching behavior for static files in the browser.
Attempts:
2 left
💡 Hint
Think about where Django looks for static files when running the development server.
component_behavior
advanced
2:00remaining
Effect of STATIC_URL on template static file links
Given STATIC_URL = '/assets/' in settings, what will be the rendered HTML output of {% static 'css/style.css' %} in a Django template?
A<link href="/media/css/style.css" rel="stylesheet">
B<link href="/static/css/style.css" rel="stylesheet">
C<link href="css/style.css" rel="stylesheet">
D<link href="/assets/css/style.css" rel="stylesheet">
Attempts:
2 left
💡 Hint
The {% static %} tag uses STATIC_URL as prefix.
📝 Syntax
advanced
1:30remaining
Correct STATICFILES_DIRS syntax
Which of the following is the correct way to set STATICFILES_DIRS in Django settings to include a folder named 'assets' inside the project root?
ASTATICFILES_DIRS = {'assets'}
BSTATICFILES_DIRS = [BASE_DIR / 'assets']
CSTATICFILES_DIRS = BASE_DIR / 'assets'
DSTATICFILES_DIRS = ('assets')
Attempts:
2 left
💡 Hint
STATICFILES_DIRS expects a list or tuple of paths.
🔧 Debug
expert
2:30remaining
Why static files not loading in production?
In production, static files are not loading even though STATIC_URL = '/static/' and STATICFILES_DIRS is set correctly. What is the most likely cause?
AThe <code>collectstatic</code> command was not run to gather static files into <code>STATIC_ROOT</code>.
BThe <code>STATIC_URL</code> is missing a trailing slash.
CThe <code>STATICFILES_DIRS</code> list contains relative paths instead of absolute paths.
DThe Django development server is running instead of a production server.
Attempts:
2 left
💡 Hint
In production, static files must be collected to one folder.