1.安装
pip install django-cors-headers
2.配置INSTALLED_APPS和MIDDLEWARE
INSTALLED_APPS = (
...
'corsheaders',
...
)
MIDDLEWARE = [ # Or MIDDLEWARE_CLASSES on Django < 1.10
...
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
...
]
注意CorsMiddleware需放在CsrfViewMiddleware 之前
3.设置CORS_ORIGIN_ALLOW_ALL
#setting.py
CORS_ORIGIN_ALLOW_ALL = True