'collectstatic' command fails when WhiteNoise is enabled

前端 未结 14 884
别那么骄傲
别那么骄傲 2020-12-08 19:51

I\'m trying to serve static files through WhiteNoise as per Heroku\'s recommendation. When I run collectstatic in my development environment, this happens:

相关标签:
14条回答
  • 2020-12-08 20:34

    The problem here is that css/iconic/open-iconic-bootstrap.css is referencing a file, open-iconic.eot, which doesn't exist in the expected location.

    When you run collectstatic with that storage backend Django attempts to rewrite all the URLs in your CSS files so they reference the files by their new names e.g, css/iconic/open-iconic.8a7442ca6bed.eot. If it can't find the file it stops with that error.

    0 讨论(0)
  • 2020-12-08 20:36

    The issue here is that using

    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

    or

    STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage

    uses Django's static file storage in a different way than runserver does. See the Django docs for some explanation: https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.manifest_strict

    I believe the referenced manifest gets built when you run collectstatic, so doing so should fix this problem temporarily, but you likely don't want to run collectstatic before every test run if you have modified any static files. Another solution would be to disable this setting for your tests, and just run it in production.

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