6
My static files work in development but not in production. How do I fix this?
Loading...
Q&A · Answered
My static files work in development but not in production. How do I fix this?
Accepted answer
# Collect static files
python manage.py collectstatic
# settings.py
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
# Use whitenoise for serving
# pip install whitenoise
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# Or use Nginx
location /static/ {
alias /path/to/staticfiles/;
}Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.