【问题标题】:Unable to run collectstatic , "references a file which could not be found: js/canvas-to-blob.min.js.map"无法运行 collectstatic ,“引用了一个找不到的文件:js/canvas-to-blob.min.js.map”
【发布时间】:2022-07-03 23:14:10
【问题描述】:

我正在尝试在 heroku 上部署一个 django react 应用程序,它使用 whitenoise 处理静态文件和 cloudinary 处理媒体文件,但是当我尝试运行 python manage.py collectstatic 它返回一个错误 'js\canvas-to-blob.min.js' 引用了一个找不到的文件,所以我使用 find static 命令查找静态文件并发现它在 virtualenv 文件夹中(venv\Lib\site-packages\cloudinary\static\js\load-image.all.min.js ) 它属于 cloudinary ,当我注释掉它的所有内容时, collectstatic 工作正常,请问有什么办法可以解决这个错误。

#installed apps
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # 'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'cloudinary_storage',
    'cloudinary',
    'rest_framework',
    'corsheaders',
    'django_summernote',
    'blog.apps.BlogConfig'
]

#cloudinary storage settings
CLOUDINARY_STORAGE = {
    'CLOUD_NAME': env('CLOUD_NAME'),
    'API_KEY': env('API_KEY'),
    'API_SECRET': env('API_SECRET'),
    'STATICFILES_MANIFEST_ROOT': BASE_DIR/'static'
}
DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage'

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

【问题讨论】:

  • 我确实面临同样的问题。
  • @davthecoder 我找到了一个临时解决方案,从 STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' 切换到 STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
  • 感谢@Dexter 让我知道,我还通过将 Django 从 4.0 降级到 3.2.10 找到了某种解决方案,我猜最新版本的 Cloudinary 与 Django 存在一些问题4.0.

标签: python django cloudinary collectstatic whitenoise


【解决方案1】:

这不是 cloudinary\static\js\load-image.all.min.js 在 vi​​rtualenv 中的真正问题。问题是 cloudinary 包显然没有提供 .map 文件cloudinary\static\js\load-image.all.min.js.map

Django 4 改变了文件发现,也可以找到源映射文件, 参见例如https://code.djangoproject.com/ticket/33353

目前,您可以使用 Django==3.2.13 并等待云端更新。

【讨论】:

    猜你喜欢
    • 2018-04-24
    • 2022-01-14
    • 2013-08-27
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2014-06-06
    相关资源
    最近更新 更多