# Werkzeug异常：405方法不允许：请求的URL不允许使用该方法

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

## 根因

请求中使用的HTTP方法不被路由允许（例如，在仅接受GET的路由上使用POST）。

## 版本兼容性

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

## 解决方案

1. **Add the correct method to the route decorator** (95% 成功率)
   ```
   @app.route('/login', methods=['GET', 'POST'])
def login():
    return "Login page"
   ```
2. **Use the correct HTTP method in the request** (90% 成功率)
   ```
   curl -X POST http://localhost:5000/login
   ```

## 无效尝试

- **Changing the request method without checking the route** — May cause other errors if the route expects specific methods. (60% 失败率)
- **Adding a catch-all route without methods** — Can override intended behavior and cause security issues. (75% 失败率)
