How to serve Django static files in production
Answered
6
My static files work in development but not in production. How do I fix this?
A
Asked by
ahmed_tech
Platinum
•
151 rep
1 Answer
15
# 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/;
}
W
Platinum
•
285 rep
Your Answer
You need to be logged in to answer questions.
Log In to Answer