[Fixed]-Django on Heroku – Broken Admin Static Files


If you use runserver and configure your app with DEBUG=True, then it will serve the admin files just like on your development machine. However, this is definitely not the recommended way to do it, and I would suggest that you put them on S3.

Using the django-storages app it’s very easy to configure collectstatic to automatically push all the admin files to S3. You can find directions here


Check out this post: http://matthewphiong.com/managing-django-static-files-on-heroku

If that doesn’t work for you try adding the following to your urls.py after the normal url pattern tuple. Make sure you have your STATIC_ROOT set and you’ve run collect static on your local environment all before pushing to heroku.

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


just add these instead

from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()

using django 1.4.1


It seems little late compared to the asked date. But I got into this issue and spent 30 mins on what I did wrong. So here it is the magic solution for those who might fall in this trap.

There is some problem with Heroku’s django.contrib.staticfiles.urls


You need to install dj-static (Link to download) on your Heroku setup.
It’s a Django middleware utility that allows to properly serve static assets from production with a WSGI server like Gunicorn.

I hope this will help someone.


create ‘static’ folder into your ‘project_directory’.

set the ‘STATIC_ROOT’ path in ‘settings.py’ file which can serve your admin-site’s static files.

STATIC_ROOT = (os.path.join(os.path.dirname(__file__), '..', 'static'))

Add STATIC_ROOT in ‘/urls.py’

from django.conf import settings
    urlpatterns += patterns('',
        url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.STATIC_ROOT,

Run the following command that will copy all the admin static files into project’s static folder.

python manage.py collectstatic

Now do git add, commit and push heroku master.


If you are deploying to Heroku without using whitenoise (which I would suggest), definitely use dj_static https://pypi.python.org/pypi/dj-static!

I spent the past 3 hours trying to serve my files to heroku and dj_static worked within a matter of 2 minutes.



I got django admin working with following edits

urls.py(at the end)

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


web: gunicorn hellodjango.wsgi -b$PORT



instead of




Follow this to fix all static related issues with Django and heroku.

In your settings.py paste this at the end

import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))


STATIC_URL = '/static/'

Your template for a particular app should be in app_name/templates/app_name/

When you render template this is how you will specify template name

in views.py

return render(request,'app_name/template_name.html',context)

For static files place your files here:




to access your static file use path app_name/css/style_name.css

If you follow this, all your static files will load up fine in heroku as well as in your local development machine.


Leave a comment