# django.core.exceptions.ImproperlyConfigured: 未设置CSRF cookie。请求失败。

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

## 根因

视图未使用@csrf_exempt，但模板中的表单缺少{% csrf_token %}，导致CSRF中间件拒绝POST请求。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Ensure the form in template includes {% csrf_token %} inside <form> tag.
   ```
2. **** (90% 成功率)
   ```
   If using AJAX, include 'X-CSRFToken' header with token from cookie.
   ```

## 无效尝试

- **** — Disables security protection for all views, causing security vulnerabilities and potential 403 errors elsewhere. (95% 失败率)
- **** — Overrides CSRF protection globally, making the app vulnerable to CSRF attacks and breaking expected behavior. (90% 失败率)
