# 禁止访问（CSRF令牌缺失或不正确）在/login/

- **ID:** `python/django-csrf-token-missing`
- **领域:** python
- **类别:** auth_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Django的CSRF保护要求在POST请求中包含有效的CSRF令牌；缺失或无效令牌导致403错误。

## 版本兼容性

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

## 解决方案

1. **Include CSRF token in template form** (95% 成功率)
   ```
   In template: {% csrf_token %} inside the <form> tags.
   ```
2. **Use @csrf_exempt decorator on specific view** (85% 成功率)
   ```
   from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def my_view(request): ...
   ```

## 无效尝试

- **Disabling CSRF globally** — Security risk; not recommended. (80% 失败率)
- **Adding @csrf_exempt to all views** — Weakens security; may not be appropriate. (70% 失败率)
