安装Django-cors-headers
GitHub:https://github.com/ottoyiu/django-cors-headers
pip install django-cors-headers
配置settings.py
INSTALLED_APPS = (
...
'corsheaders',
...
)
settings.py middleware 设置
MIDDLEWARE = [ # Or MIDDLEWARE_CLASSES on Django < 1.10
...
'corsheaders.middleware.CorsMiddleware',#放到中间件顶部
'django.middleware.common.CommonMiddleware',
...
]
新增配置
CORS_ORIGIN_ALLOW_ALL = True