dajngo cookie 修改问题设置

异常:The value of the ‘Access-Control-Allow-Origin‘ header in the response must not be the wildcard ‘*‘ when the request‘s credentials mode is‘include‘.

 

原因:

dajngo  cookie 修改问题设置

image.PNG

后台不能使用通配符 ‘*‘, 否则前端报错;

请求的 origin 和后台设置的 origin 不一致.

解决方案:

前端代码不用动.

后台 为‘Access-Control-Allow-Origin‘ 设置动态的 origin.

        response = CustomResponse(data={‘token‘: key, **serial.data}, code=200,
                              msg=‘ok‘, success=True,
                                  headers={"Access-Control-Allow-Origin":request.META.get("HTTP_ORIGIN")})

        response.set_cookie(‘hello‘,"199293",domain="192.168.96.55")
        return  response

 

其次还需要设置 settings.py :

# 允许跨域
CORS_ORIGIN_ALLOW_ALL = True
# 指明在跨域访问中,后端是否支持对cookie的操作
CORS_ALLOW_CREDENTIALS = True

前端:

axios.defaults.baseURL=‘http://192.168.96.55:8000/‘
axios.defaults.withCredentials = true;

dajngo cookie 修改问题设置

上一篇:dataTable.Select,本地检索datatable中的数据


下一篇:注释、标识符和关键字