从S3 Bucket Django导入静态文件时出错

时间:2015-10-29 12:45:53

标签: python django amazon-web-services amazon-s3

我尝试将静态和媒体文件上传到AWS S3存储桶,但是css没有被渲染。

settings.py

AWS_HEADERS = {  # see http://developer.yahoo.com/performance /rules.html#expires
    'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
    'Cache-Control': 'max-age=94608000',
}

AWS_STORAGE_BUCKET_NAME = '*'
AWS_ACCESS_KEY_ID = '*'
AWS_SECRET_ACCESS_KEY = '*'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
STATIC_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)
MEDIAFILES_LOCATION = 'media'
MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'

当我尝试通过其来源访问css文件时,我收到以下消息 -

<Error><Code>AccessDenied</Code><Message>Access Denied</Message>
<RequestId>BD606AFA0AF488B7</RequestId>
<HostId>2aZOfc5qdORtn2VhfDQsJ2gZHPoYBeBV9ciAdOnk+wGuK7azaWngXwfv+rEy1XLMFOrOgs+qDpI= </HostId>
</Error>

1 个答案:

答案 0 :(得分:1)

抱歉,这是一个愚蠢的错误。 STATICFILES_DIRS中未指定静态文件夹的根,因此collectstatic命令无法收集这些文件。