设置会话变量的CORS策略块

时间:2020-07-16 03:48:25

标签: django reactjs

我是Django的新手,目前正在使用ReactTSXDjango开发一个应用程序。我使用Django作为后端,每当尝试为请求会话变量赋值时,都会出现列出的错误。

Login Page

import Cookies from "js-cookie";

axios.request({
    url: "login/",
    baseURL: window.BACKEND_BASEURL,
    method: "POST",
    data: data,
    timeout: 15000,
    withCredentials: true,
    headers: { "X-Requested-With": "XMLHttpRequest", "X-CSRFToken": Cookies.get("csrftoken") },
    validateStatus: () => true
}).then((res: AxiosResponse): void => {

http://localhost:8000/login/

def get(r):
    r.session["user_id"] = "ME"       <-- Causing ERROR when assigning a variable

settings.py

..........
..........

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_METHODS = ["GET","POST"]
CORS_ALLOW_HEADERS = [ "accept", "accept-encoding", "authorization", "content-type", "dnt", "origin", "user-agent", "x-csrftoken", "x-requested-with" ]

..........
..........

Error

Access to XMLHttpRequest at 'http://localhost:8000/login/' from origin 'http://localhost:5000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

0 个答案:

没有答案
相关问题