[英]Django hosting static files in AWS S3 causing CORS error when trying to access admin font files
I setup Django to store all static files on S3 and with the "collectstatic" command, all the admin files where copied and when I visit the admin site the CSS and JS files are sourced from the S3 bucket correctly.我设置 Django 以将所有 static 文件存储在 S3 上,并使用“collectstatic”命令复制所有管理文件,当我访问管理站点时,CSS 和 JS 文件正确地来自 S3 存储桶。 For example:
例如:
https://bucket.s3.amazonaws.com/static/admin/css/base.css
https://bucket.s3.amazonaws.com/static/admin/js/vendor/jquery/jquery.js
But when it tries to access the Font files.woff I get the following error:但是当它尝试访问 Font files.woff 时,出现以下错误:
Access to font at 'https://bucket.s3.amazonaws.com/static/admin/fonts/Roboto-Light-webfont.woff' from origin 'http://localhost:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
It's weird that it gives me access to all the files except the font files:奇怪的是,它让我可以访问除字体文件之外的所有文件:
Configuring the following in S3 Bucket Permissions > CORS fixed the issue.在 S3 存储桶权限 > CORS 中配置以下内容修复了该问题。
[
{
"AllowedHeaders": [
"Authorization"
],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
},
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"HEAD",
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"ETag",
"x-amz-meta-custom-header"
]
}
]
I remember i faced this issue before with Google Cloud Storage.我记得我之前在使用 Google Cloud Storage 时遇到过这个问题。
You have to make your bucket allow origin cross to your domain.您必须让您的存储桶允许来源交叉到您的域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.