配置urls导包
from django.urls import path
from . import views
配置views导包
from django.shortcuts import render
from django.http import HttpResponse
跨域请求配置
INSTALLED_APPS =[
添加 ‘corsheaders’ ]
MIDDLEWARE = [
注释掉 ‘django.middleware.csrf.CsrfViewMiddleware’
再添加‘corsheaders.middleware.CorsMiddleware’
末尾添加:
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = ()
CORS_ALLOW_METHODS = (
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
'VIEW',
)
CORS_ALLOW_HEADERS = (
'XMLHttpRequest',
'X_FILENAME',
'accept-encoding',
'authorization',
'content-type',
'dnt',
'origin',
'user-agent',
'x-csrftoken',
'x-requested-with',
'Pragma',
)