Heroku – Handling static files in Django app

I found a solution. This was my initial myapp/urls.py:

from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
from django.conf import settings


admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', include('myapp.cesar.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

I added these lines to the end of the original myapp/urls.py file:

if not settings.DEBUG:
    urlpatterns += patterns('',
        (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
    )

Now it’s working fine. I hope this helps someone else too

Leave a Comment