# ImportError: 无法从 'flask' 导入名称 'current_app'

- **ID:** `python/flask-importerror-cannot-import-name-current-app`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试从 flask 导入 current_app，但它不是顶级导入；它是 flask.globals 的一部分。

## 版本兼容性

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

## 解决方案

1. **Import current_app from flask.globals.** (90% 成功率)
   ```
   from flask.globals import current_app
   ```
2. **Use app.app_context() to access current_app.** (85% 成功率)
   ```
   with app.app_context():
    from flask import current_app
    # use current_app
   ```

## 无效尝试

- **Using 'from flask import current_app' incorrectly in a script.** — current_app is available only within a request context; importing it outside causes ImportError. (70% 失败率)
- **Typo: using 'currentapp' instead of 'current_app'.** — The exact name is 'current_app'; any typo leads to ImportError. (80% 失败率)
