01-安装模块
pip install django-cors-headers
02-添加到INSTALL_APPS中
INSTALLED_APPS = ( ... 'corsheaders', ... )
03-添加中间件
'corsheaders.middleware.CorsMiddleware',
MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ]
04-设置为True
CORS_ORIGIN_ALLOW_ALL = True