Heroku - Handling static files in Django app

I have a project (myapp) in heroku but I can't get the static files to work properly. I was following this blog post.

My Procfile looks like this:

web: python myapp/manage.py collectstatic --noinput; bin/gunicorn_django --workers=4 --bind=$PORT myapp/settings.py



STATIC_ROOT = os.path.join(PROJECT_PATH, 'staticfiles')
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'

    # I have the static folder inside my app and not inside the project
    os.path.join(PROJECT_PATH, 'cesar/static'),


When restarting using heroku restart this is what the heroku logs shows:

Copying ...

114 static files copied to '/app/myapp/staticfiles'.

But when I do heroku run ls -l myapp/ I can't see the staticfiles folder:

-rw------- 1 u5605 5605    0 Jan 28 16:53 __init__.py
drwx------ 4 u5605 5605 4096 Jan 28 16:53 cesar
-rw------- 1 u5605 5605  503 Jan 28 16:53 manage.py
-rw------- 1 u5605 5605 6292 Jan 28 16:53 settings.py
drwx------ 2 u5605 5605 4096 Jan 28 16:53 templates
-rw------- 1 u5605 5605  257 Jan 28 16:53 urls.py
-rw------- 1 u5605 5605  286 Jan 28 16:53 views.py

What am I missing or doing wrong?


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


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

Probably you should manually create empty STATIC_ROOT folder specified in you settings before running './manage.py collectstatic'.

Need Your Help

How do you declare arrays in a c++ header?

c++ arrays header initialization const

This is related to some other questions, such as: this, and some of my other questions.

What are cross-browser and cross-OS safe keyboard shortcuts usable for web application?

web-applications hotkeys

I am developing a quite large web application, and it is probably a good idea to use hotkeys for some common tasks. However, I discovered that finding safe key combinations is a problem, regarding ...