Serving static files when in deployment mode with debug = false

718 views Asked by At

I have deployed my app on heroku and I am serving static files using whitenoise. Everything works perfectly, but when I turn debug=false the css stops being rendered.What could be the issue here? The static files are not be supplied by django but by whitenoise.Can't figure it out.

relevant settings.py

 STATIC_URL = '/static/'
 STATIC_ROOT = 'staticfiles'
 STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
 MEDIA_URL = '/media/'
 MEDIA_ROOT = os.path.join(BASE_DIR, "media")

project's urls.py

urlpatterns = [
url(r'^', include('watch.urls', namespace="watch")),
url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

template's static file declaration

{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'css/finale.css' %}" />
1

There are 1 answers

0
YPCrumble On

You should start by following the documentation on using WhiteNoise with Django more closely. The first difference I see is that your line:

STATIC_ROOT = 'staticfiles'

differs from the docs:

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

If following that tutorial doesn't work you should make sure to include all the relevant parts of your app (e.g., I'd need to see wsgi.py along with the files you show above) including all the WHITENOISE_XXXXXX settings in your settings.py to figure out the issue.