Cloudinary 与 scss django 冲突

问题描述 投票:0回答:1

我有一个 Django 项目,并且在设置 Cloudinary 存储和 SCSS 预处理器时遇到问题。首先,预处理器运行良好并编译文件。但是当我添加:

STATICFILES_STORAGE = 'cloudinary_storage.storage.StaticHashedCloudinaryStorage'

我收到错误:
TypeError: MediaCloudinaryStorage.__init__() got an unexpected keyword argument 'ROOT'

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'sass_processor.finders.CssFinder',
]

如果我注释掉 STATICFILES_FINDERS,我会得到一个不同的错误:

ValueError: Couldn't load manifest 'staticfiles.json' (version 1.0)

如果我尝试升级 cloudinary_storage,我会收到:

ERROR: Could not find a version that satisfies the requirement cloudinary_storage (from versions: none)
ERROR: No matching distribution found for cloudinary_storage

请告知如何正确配置Cloudinary和SCSS,以免它们发生冲突

请告知如何正确配置Cloudinary和SCSS,以免它们发生冲突

django sass cloudinary
1个回答
0
投票

假设所有其他细节都与您的代码相符,要将静态文件移动到 Cloudinary,请更新您的 settings.py:

STATIC_URL = '/static/'
STATICFILES_STORAGE = 'cloudinary_storage.storage.StaticHashedCloudinaryStorage'

然后运行

python manage.py collectstatic

请注意,默认情况下只会上传具有哈希名称的文件 - 可以通过向

--upload-unhashed-files
命令添加
collectstatic
参数来更改此行为。如果您不确定为什么向文件名添加哈希有用,简单地说,它允许 Cloudinary CDN 和 Web 浏览器安全地缓存静态文件。如果没有它,文件的修改将变得非常有问题,因为您网站的用户将使用他们的私人旧副本。散列可以防止此问题,因为任何文件更改也会更改其 url,这将迫使浏览器下载文件的新版本。

访问 https://pypi.org/project/django-cloudinary-storage/ 了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.