问题如图:
安装django-cors-headers
# 添加注册应用corsheaders
INSTALLED_APPS = [
...
'corsheaders',
...
]
# 添加中间键
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware', # 加在第一行
...
]
# 添加白名单
CORS_ORIGIN_WHITELIST = (
'http://localhost:8081',
'http://127.0.0.1:8081',
)
# 允许ajax跨域请求时携带cookie
CORS_ALLOW_CREDENTIALS = False
重启后端项目
访问http://localhost:8081/,如图数据已经展示



