# 访问 'http://localhost:5000/api' 被 CORS 策略阻止：请求的资源上没有 'Access-Control-Allow-Origin' 头。

- **ID:** `python/flask-cors-preflight-failed`
- **领域:** python
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

未安装/注册 Flask-CORS，或由于路由限制了方法导致 OPTIONS 预检请求未被处理。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   from flask_cors import CORS; CORS(app, resources={r'/api/*': {'origins': 'http://localhost:3000'}})
   ```
2. **** (85% 成功率)
   ```
   Ensure route methods include OPTIONS: @app.route('/api', methods=['GET','POST','OPTIONS'])
   ```

## 无效尝试

- **** — Preflight OPTIONS still returns 405 before after_request runs. (65% 失败率)
- **** — CORS is server-controlled; client cannot bypass it. (90% 失败率)
