# HTTP 响应错误：方法不允许（GET）：/api/data/

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

## 根因

视图未处理该 HTTP 方法（例如仅允许 POST 但请求为 GET）。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Implement method check: if request.method == 'GET': ... elif request.method == 'POST': ...
   ```
2. **** (95% 成功率)
   ```
   Use @require_http_methods(['GET', 'POST']) decorator.
   ```

## 无效尝试

- **** — Adding @require_POST to an endpoint that needs both GET and POST will block GET requests. (70% 失败率)
- **** — Changing the URL pattern without updating the view's method decorators doesn't help. (40% 失败率)
