# jinja2.exceptions.UndefinedError: 'user' 未定义

- **ID:** `python/jinja2-undefined-user`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

模板引用了未传给 render_template 或上下文字典中缺失的变量。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   return render_template('profile.html', user=current_user)
   ```
2. **** (85% 成功率)
   ```
   app.jinja_env.undefined = jinja2.StrictUndefined
   ```

## 无效尝试

- **** — Silently renders empty output instead of surfacing the missing data. (80% 失败率)
- **** — Hides the real problem and breaks required logic. (70% 失败率)
