作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试将应用程序升级到 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
工作正常,包括 collectstatic --clear
。
升级后,collectstatic --clear
失败(没有文件被删除)。collectstatic
会复制文件,但是,有时它会创建同一文件的两个版本。在这个特定的示例中,我得到了 base.hash1.css
和 base.hash2.css
。 base.hash2.css
为空,因此页面打开,但无法正确呈现。
如果我不使用 CachedFilesMixin
或 ManifestFilesMixin
,collectstatic
工作正常,但清除仍然失败。
我测试了 django 1.11 和 django-storages 的不同组合,但它们的行为似乎都一样。
其他人是否遇到过类似问题?
最佳答案
我们遇到了同样的问题。
我认为,潜在的问题有多个问题/来源:
我们通过像这样覆盖 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)
简而言之,我们在保存文件之前查找到文件的开头。
关于python - Collectstatic 创建空文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49999582/
我是一名优秀的程序员,十分优秀!