python
config_error
ai_generated
true
jinja2.exceptions.TemplateNotFound: index.html
ID: python/flask-template-not-found-error
80%Fix Rate
87%Confidence
0Evidence
2024-04-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
Root Cause
Flask 在默认模板目录 'templates' 中找不到指定的模板文件
generic中文
Flask 在默认模板目录 'templates' 中找不到指定的模板文件
Workarounds
-
95% success 创建 templates 文件夹并放置模板文件
mkdir templates && mv index.html templates/
-
90% success 在 Flask 应用中自定义模板目录
app = Flask(__name__, template_folder='custom_templates')
Dead Ends
Common approaches that don't work:
-
将模板文件放在项目根目录而非 templates 文件夹
80% fail
Flask 默认只搜索 templates 文件夹
-
修改模板路径为绝对路径但忘记更新 render_template 调用
60% fail
路径不匹配或权限问题