我正在尝试将一个应用程序升级到Django 1.11,但在使用collectstatic时遇到问题。
旧版本:
django 1.8.17
django-storages 1.5.1新版本:
django 1.11.12
django-storages 1.6.6存储:
class StaticS3BotoStorage(ManifestFilesMixin, S3BotoStorage):
location = 'static'
file_overwrite = True
preload_metadata = True或
class StaticS3BotoStorage(CachedFilesMixin, S3BotoStorage):
location = 'static'
file_overwrite = True
preload_metadata = True在旧版本中,包括collectstatic --clear在内,collectstatic工作得很好。
升级后,collectstatic --clear会失败(不会删除任何文件)。collectstatic确实会复制文件,但是,有时它会创建同一文件的两个版本。在这个特定的例子中,我得到了base.hash1.css和base.hash2.css。base.hash2.css为空,因此页面将打开,但无法正确呈现。
如果我不使用CachedFilesMixin或ManifestFilesMixin,collectstatic可以正常工作,但clear仍然失败。
我测试了django 1.11和django-storages的不同组合,但它们似乎都表现相同。
其他人也遇到过类似的问题吗?
发布于 2018-07-11 01:02:30
我们也遇到过同样的问题。
我认为,潜在的问题有多个问题/来源:
我们通过重写S3BotoStorage解决了空文件问题:
class PatchedS3StaticStorage(S3BotoStorage):
def _save(self, name, content):
if hasattr(content, 'seek') and hasattr(content, 'seekable') and content.seekable():
content.seek(0)
return super()._save(name, content)简而言之,我们在保存文件之前先查找文件的开头。
https://stackoverflow.com/questions/49999582
复制相似问题