django - CORS 标头不适用于 Django 后端 - Angular 前端
问题描述
django-cors-headers
我通过安装并按照中提到的步骤在我的 Django 后端实现了 CORS https://github.com/OttoYiu/django-cors-headers
。本质上,我执行了以下步骤-
pip install django-cors-headers
INSTALLED_APPS = ( ... 'corsheaders', ... )
MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', ... ]
CORS_ORIGIN_WHITELIST = ( 'localhost:8000', #LB '10.254.138.226:443' )
当我使用我的角度前端时,我仍然无法让它工作。例如,我的 POST 请求变成了 OPTIONS。
zone.js:2935 OPTIONS https://10.254.138.226/api/users 0 ()
error is ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: "error", …}
当我使用邮递员时,我没有这个问题。有人可以帮忙吗?
为了提供更多上下文 - 我在两台不同的机器上运行前端和后端 (DRF)。事实上,我有 2 个后端实例在两台不同的机器上运行,并且我有一个负载均衡器,将请求从<LB IP>:443
一个<Backend IP>:8000
基本 URL 映射到一个。
解决方案
我可能永远不会找到它为什么会发生的确切问题。我刚刚删除并重新创建了 LB,一切都开始自动运行。
推荐阅读
- c# - 如果与表有多个关系,则命名父实体关系 - 实体数据模型 - ADO.Net
- amazon-web-services - 使用 cloudformation 从 eks 集群在 aws 中创建 OIDC 提供程序
- shell - 如何将参数传递给 shell 脚本
- kotlin - Kotlin Coroutine Flow:如何从流中获取第一项(即文件元数据)并将其余项作为内容流传递?
- go - 如何使用 postman multipart/form-data 传递和解析嵌套对象
- snowplow - 架构:与正则表达式模式不匹配
- amazon-web-services - 如何通过 kubectl 连接在私有 PVC 上运行的 AWS RDS 数据库实例
- javascript - 在位置 0 的 json 中发送表单 -unexpected token 时出错
- caching - Outlook 加载项缓存
- javascript - 是否有可能在线性时间内获得数组中最常见的元素及其频率?