Collectstatic error while deploying Django app to Heroku
I just updated to Django 1.10 today and had the exact same problem.Your static settings are identical to mine as well.
This worked for me, run the following commands:
disable the collectstatic during a deploy
heroku config:set DISABLE_COLLECTSTATIC=1
deploy
git push heroku master
run migrations (django 1.10 added at least one)
heroku run python manage.py migrate
run collectstatic using bower
heroku run 'bower install --config.interactive=false;grunt prep;python manage.py collectstatic --noinput'
enable collecstatic for future deploys
heroku config:unset DISABLE_COLLECTSTATIC
try it on your own (optional)
heroku run python manage.py collectstatic
future deploys should work as normal from now on
You have STATICFILES_DIRS
configured to expect a static
directory in the same directory as your settings.py
file, so make sure it's there not somewhere else.
Also, do you have any files in that static
directory? If you don't then git won't track it and so although it exists locally it won't exist in git. The usual solution to this is to create an empty file called .keep
in the directory which will ensure that git tracks it. But once you have some static files in this directory then it won't be a problem anymore.
DO NOT disable collectstatic
on heroku with heroku config:set DISABLE_COLLECTSTATIC=1
. This will just hide the error and not make your app healthy.
Instead, it's better to understand why the collectstatic command fails because it means something is not right with your settings.
Step 1
Run locally both commands:
python manage.py collectstaticpython manage.py test
You should see one or more error messages. Most of the time, it's a missing variable (for ex: STATIC_ROOT
) you must add to your project settings.py
file.
It's necessary to add the test
command because some collectstatic
related issues will only surface with test
, such as this one
Step 2
Once you've fixed all the error messages locally, push again to heroku.
Troubleshooting
Remember you can also run commands directly in your heroku VM.If you cannot reproduce locally, run the collecstatic command in heroku and check what's going on directly in your production environment:
python manage.py collectstatic --dry-run --noinput
(Same goes for heroku console obviously)