github 上有详细介绍:https://github.com/ottoyiu/django-cors-headers
1、pip install django-cors-headers
# 下载
2、添加进apps
INSTALLED_APPS = [
...
'corsheaders',
...
]
3、 配置 尽量放在csrf之前
MIDDLEWARE = [ # Or MIDDLEWARE_CLASSES on Django < 1.10
...
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
...
]
4、 再
CORS_ORIGIN_ALLOW_ALL = True