0
0
Djangoframework~20 mins

WhiteNoise for static files in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WhiteNoise Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does WhiteNoise serve static files in Django?
When using WhiteNoise in a Django project, what is the main way it serves static files?
AIt serves static files directly from the Django development server without needing a separate web server.
BIt requires configuring Nginx or Apache to serve static files separately.
CIt uploads static files to a cloud storage service automatically.
DIt disables static file serving and expects the browser to cache files permanently.
Attempts:
2 left
💡 Hint
Think about how WhiteNoise simplifies static file serving in production.
📝 Syntax
intermediate
2:00remaining
Correct way to add WhiteNoise middleware in Django settings
Which option shows the correct way to add WhiteNoise middleware in the Django MIDDLEWARE list?
AWhiteNoise middleware should be added inside INSTALLED_APPS, not MIDDLEWARE.
B'whitenoise.middleware.WhiteNoiseMiddleware' should be added at the bottom of the MIDDLEWARE list.
C'whitenoise.middleware.WhiteNoiseMiddleware' should be added at the top of the MIDDLEWARE list.
D'django.middleware.security.SecurityMiddleware' should be replaced by 'whitenoise.middleware.WhiteNoiseMiddleware'.
Attempts:
2 left
💡 Hint
Middleware order matters for WhiteNoise to work properly.
🔧 Debug
advanced
3:00remaining
Why are static files not served with WhiteNoise in production?
Given this Django production setup with WhiteNoise configured, static files are not loading. What is the most likely cause?
Django
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    # other middleware
]

STATIC_ROOT = '/var/www/static/'

# collectstatic has been run

# DEBUG = False
AWhiteNoise middleware is placed after SecurityMiddleware, which is incorrect.
BSTATICFILES_STORAGE is not set to 'whitenoise.storage.CompressedManifestStaticFilesStorage'.
CDEBUG is set to True, so WhiteNoise does not serve static files.
DSTATIC_ROOT is missing trailing slash, causing path errors.
Attempts:
2 left
💡 Hint
Check if static files are compressed and cached properly in production.
state_output
advanced
2:30remaining
What happens when you run collectstatic with WhiteNoise?
After configuring WhiteNoise and running 'python manage.py collectstatic', what is the expected state of the static files?
AStatic files are copied to STATIC_ROOT with compressed and hashed filenames for caching.
BStatic files remain in their original app directories without changes.
CStatic files are uploaded to a CDN automatically.
DStatic files are deleted from the project to save space.
Attempts:
2 left
💡 Hint
Think about how WhiteNoise helps with caching static files.
🧠 Conceptual
expert
3:00remaining
Why choose WhiteNoise over a separate static file server?
What is the main advantage of using WhiteNoise to serve static files in a Django app compared to using a separate web server like Nginx?
AIt automatically scales static file serving across multiple servers without extra setup.
BIt encrypts static files during transfer for better security.
CIt improves static file delivery speed beyond what Nginx can provide.
DIt simplifies deployment by removing the need to configure and maintain a separate static file server.
Attempts:
2 left
💡 Hint
Think about deployment complexity and maintenance.