django 解决跨域问题

1)安装django-cors-headers模块

2)在settings.py中配置
# 注册app
INSTALLED_APPS = [
...
'corsheaders'
]
3)添加中间件
MIDDLEWARE = [
  'corsheaders.middleware.CorsMiddleware'
]
4)允许跨域源
CORS_ORIGIN_ALLOW_ALL = True

5)上线配置指定域名

CORS_ORIGIN_WHITELIST = [

"heep://test.com"

]

猜你喜欢

转载自www.cnblogs.com/Chinesehan/p/12933746.html