【发布时间】:2014-02-26 05:04:51
【问题描述】:
我正在使用 django-pipeline + django-storage 和一个 S3 后端,但我在尝试加载我的正确使用 {% static %} 标签的静态文件。
我阅读并遵循了管道文档:http://django-pipeline.readthedocs.org/en/latest/storages.html#using-with-other-storages
我创建了以下混合类:
from django.contrib.staticfiles.storage import CachedFilesMixin
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
pass
在我的生产设置文件中:
AWS_QUERYSTRING_AUTH = False
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = 'myapp.S3PipelineStorage'
AWS_ACCESS_KEY_ID = 'xxx'
AWS_SECRET_ACCESS_KEY = 'xxx
AWS_STORAGE_BUCKET_NAME = 'mybucket'
from datetime import datetime, timedelta
AWS_HEADERS = {
'Expires': (datetime.now() + timedelta(days=365*10)).strftime('%a, %d %b %Y 00:00:00 GMT')
}
STATIC_URL = 'https://mybucket.s3.amazonaws.com/'
STATIC_ROOT = ''
当我使用这些设置运行 collectstatic 时,一切正常,但使用:
{% static 'path/file.xxx' %}
我得到一个包含查询字符串身份验证的 URL,尽管我在 AWS_QUERYSTRING_AUTH 中设置了 False,因此我的静态文件没有加载……通过删除该查询字符串,我可以正确加载它们。
我还尝试在myapp.S3PipelineStorage 中设置“querystring_auth = False”,但它似乎被忽略了:(
为什么不遵守设置?什么是删除该 qs 的有效解决方案? (我正在考虑使用自定义过滤器将其剥离……但我讨厌编写这样的“补丁”)……最后,如果我必须保留该身份验证查询字符串,为什么不工作?如何调试此行为?
编辑: 它有效……这是一个与缓存有关的问题:|
【问题讨论】:
标签: django amazon-s3 django-storage django-pipeline