# django.core.exceptions.ImproperlyConfigured: CSRF middleware must be placed before any view middleware that uses CSRF token.

- **ID:** `python/django-middleware-order-error`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

MIDDLEWARE设置中CSRF中间件顺序错误

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   确保'django.middleware.csrf.CsrfViewMiddleware'在SessionMiddleware之后
   ```
2. **** (90% success)
   ```
   从Django项目模板复制默认MIDDLEWARE设置
   ```

## Dead Ends

- **** — 会导致CSRF保护失效，存在安全风险 (90% fail)
- **** — 顺序错误，无法正确设置CSRF令牌 (80% fail)
