启用WhiteNoise时,'collectstatic'命令失败

Pie*_*ter 24 python django static-files python-3.x

我正在尝试按照Heroku的建议通过WhiteNoise提供静态文件.当我在我的开发环境中运行时,会发生这种情况:collectstatic

Post-processing 'css/iconic/open-iconic-bootstrap.css' failed!

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/base.py", line 533, in handle
    return self.handle_noargs(**options)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs
    collected = self.collect()
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 120, in collect
    raise processed
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 242, in post_process
    content = pattern.sub(converter, content)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 181, in converter
    hashed_url = self.url(unquote(joined_result), force=True)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 128, in url
    hashed_name = self.stored_name(clean_name)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 277, in stored_name
    cache_name = self.clean_name(self.hashed_name(name))
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 91, in hashed_name
    (clean_name, self))
ValueError: The file 'css/fonts/open-iconic.eot' could not be found with <whitenoise.django.GzipManifestStaticFilesStorage object at 0x7f57fc5b1550>.
Run Code Online (Sandbox Code Playgroud)

当我在我的设置中注释掉这一行时,静态收集命令会毫无问题地运行:

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
Run Code Online (Sandbox Code Playgroud)

这里出了什么问题,我该如何解决?我已经尝试清空我的静态文件输出文件夹.它运行顺利,直到它开始处理一个特定文件.

D. *_*ans 16

这里的问题css/iconic/open-iconic-bootstrap.css是引用一个文件open-iconic.eot,该文件在预期的位置不存在.

当您collectstatic使用该存储后端运行时,Django会尝试重写CSS文件中的所有URL,以便它们通过新名称引用文件,例如,css/iconic/open-iconic.8a7442ca6bed.eot.如果找不到该文件,则会因该错误而停止.

  • 谢谢你的解释.但是,你还知道有什么方法可以解决这个问题吗?虽然显然仍在使用WhiteNoise. (5认同)
  • 不,这不是WhiteNoise特有的:如果你使用`django.contrib.staticfiles.storage.CachedStaticFilesStorage`,你会发现你得到它.您不必使用存储后端来使用WhiteNoise,它只会让您获得更好的性能. (4认同)

use*_*401 11

我刚刚遇到了同样的问题并通过从我的设置文件中删除此行来修复它,

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
Run Code Online (Sandbox Code Playgroud)

我从Heroku文档页面得到了这一行......

  • @BernardParah,您正在从whitenoise禁用[压缩和缓存支持](http://whitenoise.evans.io/en/stable/django.html#add-compression-and-caching-support)。您不需要使用白噪声,但这很好。 (2认同)

Aur*_*raf 7

当我所有的.css文件都存在时,我有这个错误声称缺少.css文件,因为我信任Heroku文档:

STATIC_ROOT = 'staticfiles'
Run Code Online (Sandbox Code Playgroud)

在WhiteNoise文档:

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Run Code Online (Sandbox Code Playgroud)

修复是微不足道的,但在Heroku修复他们的文档(我提交反馈)之前,让我们确保解决方案至少出现在SO中.


sol*_*oke 7

在较新版本的白噪声中,只有两种可用的存储类别:

  • whitenoise.storage.CompressedManifestStaticFilesStorage
  • whitenoise.storage.CompressedStaticFilesStorage

CompressedManifestStaticFilesStorage如果您的任何静态资源引用静态文件查找器无法找到的其他资源,则会出现此错误。这是因为它HashedFilesMixin会解析所有文件以查找对其他资产的引用,以便它可以为所有文件预先生成哈希值以添加到清单中。

有两种方法可以解决这个问题:

  1. 切换到使用CompressedStaticFilesStorage(no Manifest),这样文件哈希值就不会被预渲染。

  2. 识别在收集静态期间报告的所有丢失文件,并确保它们存在于您收集的目录中,或者删除静态文件中对它们的引用。

  • 从你的酷应用程序中删除白噪声是没有意义的。在许多不相关的答案中,这个答案是唯一对我有用的解决方案。 (2认同)