python
config_error
ai_generated
true
模板未找到错误:index.html
jinja2.exceptions.TemplateNotFound: index.html
ID: python/flask-template-not-found-error
80%修复率
87%置信度
0证据数
2024-04-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
根因分析
Flask 在默认模板目录 'templates' 中找不到指定的模板文件
English
Flask 在默认模板目录 'templates' 中找不到指定的模板文件
解决方案
-
95% 成功率 创建 templates 文件夹并放置模板文件
mkdir templates && mv index.html templates/
-
90% 成功率 在 Flask 应用中自定义模板目录
app = Flask(__name__, template_folder='custom_templates')
无效尝试
常见但无效的做法:
-
将模板文件放在项目根目录而非 templates 文件夹
80% 失败
Flask 默认只搜索 templates 文件夹
-
修改模板路径为绝对路径但忘记更新 render_template 调用
60% 失败
路径不匹配或权限问题