to install django-cors-headers and add it to installed apps in settings.py
1 2 3 4 5
INSTALLED_APPS = [ ..., "corsheaders", ..., ]
Add a middleware class to listen in on responses. The order of middlewares is important:
CorsMiddleware should be placed as high as possible, especially before any middleware that can generate responses such as Django’s CommonMiddleware or Whitenoise’s WhiteNoiseMiddleware. If it is not before, it will not be able to add the CORS headers to these responses.
Also if you are using CORS_REPLACE_HTTPS_REFERER it should be placed before Django’s CsrfViewMiddleware.
//django use cookies to varify csrf importVueCookiesfrom'vue-cookies' Vue.use(VueCookies) //`withCredentials` indicates whether or not cross-site Access-Control requests should be made using credentials axios.defaults.withCredentials = true