我是Django
的新手,目前正在使用ReactTSX
和Django
开发一个应用程序。我使用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.