You need to enable JavaScript to run this app. Django使用whitenoise托管静态文件时collectstatic报错如何解决
优惠活动
大模型
产品
解决方案
定价
更多

Django使用whitenoise托管静态文件时collectstatic报错如何解决

错误原因

  • 核心问题是类名拼写错误:你配置的CompressedMainfestStaticFilesStorage拼写有误,正确类名为CompressedManifestStaticFilesStorage,你误将Manifest(意为清单)写为Mainfest,导致Python导入时无法在whitenoise.storage模块中找到对应类。
  • 若拼写修正后仍报错,可能是whitenoise版本过旧或安装不完整,或是Django版本(4.2+)已废弃STATICFILES_STORAGE配置项导致兼容性问题。

处理方案

  1. 先修正STATICFILES_STORAGE的拼写错误:
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  1. 如果你使用的是Django 4.2及以上版本,需要用新版STORAGES配置项替代已废弃的STATICFILES_STORAGE参数,配置如下:
STORAGES = {
    "default": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
    },
    "staticfiles": {
        "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
    }
}
  1. 若修正拼写和配置格式后仍有异常,执行以下命令升级whitenoise到最新稳定版:
pip install --upgrade whitenoise
  1. 完成上述修改后重新执行python manage.py collectstatic即可正常运行。

内容的提问来源于stack exchange,提问作者Chandan Raj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.15 10:45:04