Django Heroku not serving static files when Debug=False

Viewed 2845

I'm hosting my Django application on Heroku and using whitenoise to handle serving static files.

Following is content of settings.py

DEBUG = False

ALLOWED_HOSTS += [
    'example.com',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    ...
]

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static_my_project')
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static_cdn', 'static_root')

But static files are not working.

Setting Debug=True is serving static files but not when Debug=False.

2 Answers

Got the solution from a post

Added collectstatic to Procfile

web: python manage.py collectstatic --no-input; gunicorn myapp.wsgi --log-file - --log-level debug

And now every static file is serving including, CSS, js, images and videos.

Related