# AttributeError: 'NoneType'对象没有属性'is_authenticated'

- **ID:** `python/flask-login-user-loader-none`
- **领域:** python
- **类别:** auth_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Flask-Login的user_loader对会话中的用户ID返回了None，通常发生在用户被删除后。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   @login_manager.user_loader\ndef load(uid):\n    return db.session.get(User, int(uid))\n# template: {% if current_user.is_authenticated %}
   ```
2. **** (90% 成功率)
   ```
   if not current_user.is_authenticated:\n    logout_user()
   ```

## 无效尝试

- **** — Disables protection but current_user remains None. (80% 失败率)
- **** — Bypasses auth checks and creates security holes. (90% 失败率)
