1. 安装
pip3 install django-cors-headers
2.在settings.py里设置
INSTALLED_APPS = ( ... 'corsheaders', ... )
3.在settings.py的middleware里设置
MIDDLEWARE = [ # Or MIDDLEWARE_CLASSES on Django < 1.10 ... 'corsheaders.middleware.CorsMiddleware',#放到中间件顶部 'django.middleware.common.CommonMiddleware', ... ]
4.在settings.py新增加配置
CORS_ORIGIN_ALLOW_ALL = True