Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku collectstatic not run during deployment

I have a django app that I am successfully deplying to heroku. When I dry-run the collectstatic command locally everything works fine.

python manage.py collectstatic --dry-run --noinput
....
Pretending to copy '/Users/hari/.virtualenvs/bsc2/lib/python2.7/site-packages/django/contrib/admin/static/admin/js/admin/ordering.js'
Pretending to copy '/Users/hari/.virtualenvs/bsc2/lib/python2.7/site-packages/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js'

71 static files copied.

Despite this ..my django admin staticfiles do not get used and I get a bare-bones django admin site on heroku with Debug set to False.

If I set Debug to True I get a "rich" admin site on heroku. With Debug set to True or False "git push heroku master " command terminal output does not have anything about collecting staticfiles.

I tried the example "helloworld" application that uses gunicorn from Heroku and that did display the "collecting static" messages.I also tried inserting this code snippet into my urls.py. But that too does not help.

from django.conf import settings

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

Next, I tried adding the following to my heroku config

heroku config:add DISABLE_COLLECTSTATIC=0

But that too did not show my django admin site with all the styles.

Finally I tried switching to gunicorn with my Procfile and that also did not show the admin styles. Only setting Debug=True works to show my admin styles.

I tried this with Django 1.4.2 and 1.5.1 on Heroku and neither is showing me a "normal" admin site. Is there any way out to have my admin files on heroku without going the S3 route.

like image 921
harijay Avatar asked Apr 06 '13 21:04

harijay


1 Answers

command terminal output does not have anything about collecting staticfiles.

Looking at heroku-buildpack-python:bin/steps/collectstatic it seems that it tries to do a collectstatic --dry-run --noinput and pipes it's output to /dev/null before displaying the -----> Collecting static files message. This means that if there is an error there that is not present on your local box, you will never see the error on heroku : it will silently fail. (The best kind of failure ;)

have you tried running a one-off worker to test out the collectstatic command and see if it's a problem in their environment?

heroku run python manage.py collectstatic --dry-run --noinput

If this fails, it will give you an error or traceback to look into and further diagnose the issue.

like image 91
Thomas Avatar answered Sep 28 '22 02:09

Thomas