# Werkzeug异常：405方法不允许

- **ID:** `python/flask-method-not-allowed-error`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

请求的URL存在但不支持使用的HTTP方法（例如，对仅GET的路由使用POST）。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Specify allowed methods explicitly: @app.route('/submit', methods=['POST'])
   ```
2. **** (90% 成功率)
   ```
   Use method checking in the view: if request.method == 'POST':\n    # handle POST\nelse:\n    abort(405)
   ```

## 无效尝试

- **** — Catching MethodNotAllowed and redirecting to the same URL can cause infinite loops. (70% 失败率)
- **** — Changing the route to accept all methods may expose unintended functionality. (80% 失败率)
