# 模板未找到错误：index.html

- **ID:** `python/flask-template-not-found-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Flask 在默认模板目录 'templates' 中找不到指定的模板文件

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## 解决方案

1. **创建 templates 文件夹并放置模板文件** (95% 成功率)
   ```
   mkdir templates && mv index.html templates/
   ```
2. **在 Flask 应用中自定义模板目录** (90% 成功率)
   ```
   app = Flask(__name__, template_folder='custom_templates')
   ```

## 无效尝试

- **将模板文件放在项目根目录而非 templates 文件夹** — Flask 默认只搜索 templates 文件夹 (80% 失败率)
- **修改模板路径为绝对路径但忘记更新 render_template 调用** — 路径不匹配或权限问题 (60% 失败率)
