- 引入django-cors-headers: pip3 install django-cors-headers
添加到INSTALLED_APPS中:
# settings.py
INSTALLED_APPS = [
......
'corsheaders',
]
配置MIDDLEWARE,添加的跨域配置尽量放在’django.middleware.csrf.CsrfViewMiddleware’之前
# settings.py
MIDDLEWARE = [
......
'corsheaders.middleware.CorsMiddleware',
]
配置CORS_ORIGIN_ALLOW_ALL = True