How To Serve Django Static Files On Heroku With Gunicorn
I have an app in Django, I deployed it on heroku but I am unable to serve static files on the server and below are my code and settings: settings.py DEBUG = True TEMPLATE_DEBUG = D
Solution 1:
While deploying your app first change DEBUG=FALSE
in your setting file.
Following link can be useful.
https://devcenter.heroku.com/articles/django#deploy-to-heroku
Solution 2:
To serve static files I highly recommend you to use whitenoise http://whitenoise.evans.io/en/stable/django.html
STATIC_ROOT = os.path.join(PROJECT_PATH, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'MIDDLEWARE_CLASSES = [
# 'django.middleware.security.SecurityMiddleware','whitenoise.middleware.WhiteNoiseMiddleware',
# ...
]
No need to run collectstatic
as heroku will do that for you. What that does is puts all the files into the STATIC_ROOT
for you (all compressed and with a hashed file name for long expires).
Post a Comment for "How To Serve Django Static Files On Heroku With Gunicorn"