django存储uploades到amazon s3但从网站访问时显示错误

时间:2017-06-13 19:38:23

标签: django amazon-s3 boto boto3 django-storage

我有一个单页应用程序,它使用Vuejs和django作为其后端。我使用django-storages和boto3来存储文件。我已经安装了aws cli并设置了凭据。同样在我的项目设置中添加了这些:

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
AWS_STORAGE_BUCKET_NAME = 'mybucket-name-static'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

我可以运行collectstatic,它会上传到我的存储桶。但是,没有静态文件下载到浏览器中。如果我检查网站中静态文件的URL,则会在网址上附加额外的字符串,并打开这些网址会显示错误消息:

<Error>
    <script id="tinyhippos-injected"/>
    <Code>PermanentRedirect</Code>
    <Message>
        The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
    </Message>
    <Bucket>mybucket-name-static</Bucket>
    <Endpoint>mybucket-name-static.s3.amazonaws.com</Endpoint>
    <RequestId>xdxdxxdxd</RequestId>
    <HostId>
        YmH2sBIsddvdrdSxrp8viWZBIoZFlfqUpp6YGJHgVkMH2Vh4AOZP9xeUoezJI0Y=
    </HostId>
</Error>

的index.html:

{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="{% static "favicons/favicon.ico" %}" type="image/x-icon">
    <link rel="icon" href="{% static "favicons/favicon.ico" %}" type="image/x-icon">
    <title>app</title>
    <link href="{% static "css/app.7759951d6d7e8ca6b5f586cdd9b55f3b.css" %}" rel=stylesheet>
</head>
<body>
    <div id="app"></div>

    <script type="application/javascript" src="{% static "js/manifest.862a9db37e07dc2a85b7.js" %}"></script>
    <script type="application/javascript" src="{% static "js/vendor.09e075a2fb63be36f883.js" %}"></script>
    <script type="application/javascript" src="{% static "js/app.f6fac1f9f25fe4014887.js" %}"></script>
</body>
</html>
你能帮我解决一下吗?我在这里缺少什么?

0 个答案:

没有答案