【发布时间】:2019-02-17 23:01:35
【问题描述】:
我已经将文件上传到 S3,我的 Wagtail/django 应用程序(静态和上传)工作正常。现在我正在尝试使用ManifestStaticFilesStorage 来启用缓存清除。应用程序正在正确生成 url,并且正在将带有哈希的文件复制到 S3。
但每次我运行collectstatic 时,有些文件会被复制两次到 S3 - 每个文件都有不同的哈希值。到目前为止,所有 CSS 文件都存在此问题。
file.a.css 由应用程序加载,是 staticfiles.json 中引用的文件 - 但它是 S3 中的 20.0B 文件(应为 6.3KB)。
file.b.css 在 S3 中具有正确的内容 - 但是它不会出现在 collectstatic 生成的输出中。
# custom_storages.py
from django.conf import settings
from django.contrib.staticfiles.storage import ManifestFilesMixin
from storages.backends.s3boto import S3BotoStorage
class CachedS3Storage(ManifestFilesMixin, S3BotoStorage):
pass
class StaticStorage(CachedS3Storage):
location = settings.STATICFILES_LOCATION
class MediaStorage(S3BotoStorage):
location = settings.MEDIAFILES_LOCATION
file_overwrite = False
部门:
"boto==2.47.0",
"boto3==1.4.4",
"django-storages==1.5.2"
"Django==2.0.8"
任何有关在何处查找此问题的指针将不胜感激! :)
编辑:
更仔细地查看复制到 S3 的所有文件,问题仅发生在 CSS 文件中。
禁用将资产推送到 S3 并将它们写入本地文件系统可以按预期工作。
编辑 2:
将所有部门更新到最新版本 - 与上述行为相同。
【问题讨论】:
-
您是否尝试在 prod 上重新启动 Django?
-
我做过...很多次:p
标签: django amazon-s3 boto3 wagtail django-storage