How to serve Django static files in production

Answered
Jan 05, 2026 912 views 1 answers
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
Answered by web_developer 1 week, 2 days ago
Platinum 285 rep

Your Answer

You need to be logged in to answer questions.

Log In to Answer