- requirements.txt添加一行,django-cors-headers==2.0.1
- 控制台,运行 pip install -r requirements.txt
- 在conf/default.py文件中,INSTALLED_APPS中添加 ‘corsheaders’
- 在conf/default.py文件中,INSTALLED_APPS下边添加:
if ENVIRONMENT != "production":
MIDDLEWARE_CLASSES = (
'corsheaders.middleware.CorsMiddleware',
#'account.middlewares.DisableCSRFCheck',
) + MIDDLEWARE_CLASSES
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = (
'dev.**', #允许请求的host
'dev.**:8005', #允许请求的host
)
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_METHODS = (
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
)