0

我正在使用django-pipeline + django-storageS3后端,但我正在疯狂地尝试使用{% 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,尽管我设置FalseAWS_QUERYSTRING_AUTH,因此我的静态文件没有加载……通过删除该查询字符串,我可以正确加载它们。我也尝试设置“ querystring_auth = Falsemyapp.S3PipelineStorage,但它似乎被忽略了:(

为什么不尊重设置?什么是删除 qs 的有效解决方案?(我正在考虑使用自定义过滤器将其剥离……但我讨厌编写这样的“补丁”)……最后,如果我必须保留该身份验证查询字符串,为什么不起作用?如何调试此行为?

编辑:它有效......这是与缓存有关的问题:|

4

1 回答 1

0

看看这个答案。也许这是顺序问题(例如 django-storages 会覆盖您的设置)。也许尝试设置每个桶?

于 2014-02-02T19:26:06.937 回答