1、安装
pip install django-cors-headers
2、添加应用
INSTALLED_APPS = (
…
‘corsheaders’,
…
)
3, 中间层设置
MIDDLEWARE = [
‘corsheaders.middleware.CorsMiddleware’,
…
]
4, 添加白名单(添加了白名单的才可以访问此项目,如果添加了也不行,可以尝试在域名前面添加http://)
#CORS
CORS_ORIGIN_WHITELIST = (
‘127.0.0.1:8080’,
‘localhost:8080’,
‘www.meiduo.site:8080’,
‘api.meiduo.site:8000’
)
CORS_ALLOW_CREDENTIALS = True # 允许携带cookie