Vue + Django 使用wangeditor 上传图片 显示跨域报错
报错:
newsDetailed:1 Access to XMLHttpRequest at 'http://www.py32api.com:8000/users/uploadFile/' from origin 'http://localhost:8080' has been blocked by CORS policy: Request header field token is not allowed by Access-Control-Allow-Headers in preflight response.
解决办法:
editor_instance = new WangEditor(editor.value);
// 查看这里设置的请求头
editor_instance.config.uploadImgHeaders = {
Token: getToken() // 设置请求头,通过Cookies 二次封装的getToken 函数获取
}
# 在django的setting.py里加上对应的
CORS_ALLOW_HEADERS = (
'token',
'...',
)