[Fixed]-Only Static IMAGES not showing up on Django application? Deployed to Heroku and using S3

1👍

To enable images to load when DEBUG=False, do the following in your urls.py file

from django.conf.urls import url

from django.views.static import serve

and then add those two urls in urlpatterns:

url(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),

url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),

assuming that your MEDIA_URL = 'media' and STATIC_URL='static'

0👍

serving static files is actually one of the things that Django makes incredibly complicated and fraught with hazard. the recommended way is here: https://docs.djangoproject.com/en/1.9/howto/static-files/, and here https://docs.djangoproject.com/en/1.9/howto/static-files/deployment/. I ended up making a show_static view and a pattern that matched the static pages, so just put url(static_pattern, views.show_static) in my urls.py.

Leave a comment