Heroku collectstatic not run during deployment

前端 未结 4 1254
时光取名叫无心
时光取名叫无心 2020-12-19 12:41

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 colle         


        
相关标签:
4条回答
  • 2020-12-19 13:30

    Check this out Django and Static Assets. It seems to be updated recently and you can serve static files nicely using this dj-static package.

    0 讨论(0)
  • 2020-12-19 13:33

    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.

    0 讨论(0)
  • 2020-12-19 13:34

    throwing it out there, since dumb mistakes happen:

    I spent much time trying to figure out why my module wasn't found on heroku when it was working fine locally, only to realize it was ignored by an entry into .slugignore

    0 讨论(0)
  • 2020-12-19 13:42

    Try these three things:

    • Create this Heroku config variable: DJANGO_SETTINGS_MODULE with a value of myapp.settings.prod--or as appropriate for your Heroku settings file
    • Use Whitenoise as described in the Heroku docs: https://devcenter.heroku.com/articles/django-assets
    • Check it in and redeploy your dyno: git push heroku master

    I found I was missing the first item, the DJANGO_SETTINGS_MODULE" e.g., Command line collectstatic would work but that didn't matter b/c it was an ephemeral dyno

    0 讨论(0)
提交回复
热议问题