我正在将Django SummerNote用于我的文本字段。这会使我的文本字段看起来有点像下面的图像
现在,上面的静态文件存储在我的AWS S3存储桶中。我得到一个
403 error
在浏览器控制台和下面是我的文本字段现在的样子
控制台中的403错误如下
跨源请求被阻止:同一源策略不允许读取位于的远程资源
https://some_bucket_66d.s3.amazonaws.com/static/summernote/font/summernote.woff?1d9aeaaff0a8939558a45be6cd52cd4c
. (原因:CORS头访问控制允许源丢失)。[了解更多信息]
可下载字体:下载失败(字体系列:“SummerNote”样式:Normal Weight:400 Stretch:100 SRC Index:1):错误的URI或不允许跨站点访问的源:
https://some_bucket_6d.s3.amazonaws.com/static/summernote/font/summernote.woff?1d9aeaaff0a8939558a45be6cd52cd4c
所以为了解决这个错误,我做了
pip install django-cors-headers
补充
INSTALLED_APPS = (
...
'corsheaders',
...
]
添加到我的中间件
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
...
]
并在Django设置中添加以下3个指向我的Whitlist的链接。我不知道什么
http://127.0.0.1:9000
是为了但我只是让它在任何地方,因为它在
https://pypi.org/project/django-cors-headers/
页
CORS_ORIGIN_WHITELIST = [
"https://some_bucket_66d.s3.amazonaws.com", #This is the bucket path as you see in the error above
"http://localhost:8080",
"http://127.0.0.1:9000"
]
即使在Django Cors中将它白列出来,我仍然会得到同样的错误:我做错了什么?我如何修复它?
尝试了@jusrdare建议的解决方案。现在错误消息已更改为以下内容
downloadable font: download failed (font-family: "summernote" style:normal weight:400 stretch:100 src index:1): status=2147746065 source: https://some_bucket_66d.s3.amazonaws.com/static/summernote/font/summernote.woff?1d9aeaaff0a8939558a45be6cd52cd4c
如果你不想做通婚起源
*
您可以尝试以下代码
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://www.your-site.com</AllowedOrigin>
<AllowedOrigin>https://www.your-site.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
</CORSRule>
</CORSConfiguration>
不管怎样,他们都给了我同样的错误