Django collectstatic from Heroku pushes to S3 everytime

前端 未结 6 1414
忘了有多久
忘了有多久 2021-02-02 01:23

I\'m using django-storages for static files with S3 (and S3BotoStorage). When I do collectstatic from my local machine, the behaviour is as expected, where only modified files a

6条回答
  •  忘了有多久
    2021-02-02 02:03

    I agree this is annoying- there's a couple things you can do. I override the collectstatic command and wire it up in my production settings. Below is the command I use:

    ```

    from django.core.management.base import BaseCommand
    class Command(BaseCommand):
        args = '< none >'
        help = "disables collectstatic cmd in contrib"
        def handle(self, *args, **kwargs):
            print 'collectstatic disabled'
    

    ```

    I keep this in mysite/disablecollectstatic/management/commands Then in production settings:

    INSTALLED_APPS += ('mysite.disablecollectstatic',)
    

    Alternatively you could use the fact that Heroku does a dry run first before actually invoking the command. If it fails, it won't run it, which means you could contrive an error (by maybe deleting the static root in your settings, for example) but this approach makes me nervous:

    https://devcenter.heroku.com/articles/django-assets#detection

提交回复
热议问题