【发布时间】: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