Collectstatic error while deploying Django app to Heroku

风流意气都作罢 提交于 2019-11-28 15:44:44
tomcounsell

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:

  1. disable the collectstatic during a deploy

    heroku config:set DISABLE_COLLECTSTATIC=1

  2. deploy

    git push heroku master

  3. run migrations (django 1.10 added at least one)

    heroku run python manage.py migrate

  4. run collectstatic using bower

    heroku run 'bower install --config.interactive=false;grunt prep;python manage.py collectstatic --noinput'

  5. enable collecstatic for future deploys

    heroku config:unset DISABLE_COLLECTSTATIC

  6. 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.

Run python manage.py collectstatic locally and fix any errors. In my case there were reference errors that prevented that command from running successfully.

It seems to me that it's having problems creating that blogproject/static folder. I see you have a static folder inside your blog app, but it should be up one level in your blogproject folder.

Try creating a static folder inside your blogproject folder and that error should go away.

this worked for me:

heroku config:set DISABLE_COLLECSTATIC=1

and after:

git push heroku master

Heroku had made a document with suggestions on how to handle this https://devcenter.heroku.com/articles/django-assets

add to settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
 STATIC_URL = '/static/'
 STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

make a directory in the root of your project called staticfiles, put a favicon or something in there, just make sure git tracks it. Then the collectstatic command should finish on heroku.

Today, not all of the requirements came in properly with $ pipenv install django from the heroku-django-template and $ pip install -r requirements.txt.

The latest version of the template includes a /static folder with a humans.txt, so the previous solution is likely not the proplem

Try running $ pipenv install whitenoise and then $ pip freeze > requirements.txt.

If that works, I would recommend $ pip install psycopg2 --ignore-installed and $ pip freeze > requirements.txt as well, otherwise you will similarly have problems migrating.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!