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',
    '...',
)

 

posted @ 2023-12-22 10:11  笑而不语心自闲  阅读(134)  评论(0编辑  收藏  举报