报错信息
Access-Control-Allow-Origin' header is present on the requested resource.
解决:
1,安装
pip install django-cors-headers
2 ,添加配置
# CORS组的配置信息
CORS_ORIGIN_WHITELIST = (
'http://localhost:9528',
)
# 允许ajax跨域请求时携带cookie
CORS_ALLOW_CREDENTIALS = True
# 添加应用
INSTALLED_APPS = [
...
'corsheaders',
...
]
#中间件
MIDDLEWARE = [
#必须写在第一个位置
'corsheaders.middleware.CorsMiddleware',
...
]