- 安装
pip install django-cors-headers
- 添加允许访问Django的域名
# 允许哪些域名访问django # ALLOWED_HOSTS = [] ALLOWED_HOSTS = ['127.0.0.1', 'localhost']
- 添加应用
INSTALLED_APPS = ( ... 'corsheaders', ... )
- 设置中间层
MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', ... ]
- 添加白名单
# CORS CORS_ORIGIN_WHITELIST = ( '127.0.0.1:8080', 'localhost:8080', 'www.meiduo.site:8080', 'api.meiduo.site:8000' ) CORS_ALLOW_CREDENTIALS = True # 允许携带cookie
做一个Django项目(1.4、跨域请求问题)
最新推荐文章于 2023-03-23 17:17:41 发布