python
config_error
ai_generated
true
jinja2.exceptions.TemplateNotFound: 未找到模板index.html
jinja2.exceptions.TemplateNotFound: index.html
ID: python/flask-template-not-found
80%修复率
89%置信度
0证据数
2024-08-28首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.x | active | — | — | — |
| 3.x | active | — | — | — |
根因分析
模板文件不在配置的templates目录中,或者Flask应用使用了不同的根路径创建。
English
Template file missing from the configured templates folder, or the Flask app was created with a different root path.
解决方案
-
95% 成功率
app = Flask(__name__, template_folder='templates')
-
92% 成功率
import os\napp = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), 'templates'))
无效尝试
常见但无效的做法:
-
90% 失败
Reload flag only affects caching, not missing files.
-
50% 失败
Works but bypasses template inheritance and is unmaintainable.