python
config_error
ai_generated
true
jinja2.exceptions.TemplateNotFound: index.html
ID: python/starlette-template-not-found
80%修复率
88%置信度
0证据数
2024-04-21首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
Jinja2Templates 目录不包含该模板,或目录路径相对于工作目录错误。
English
Jinja2Templates directory does not contain the template, or the directory path is wrong relative to the working directory.
解决方案
-
93% 成功率
templates = Jinja2Templates(directory=Path(__file__).parent / 'templates')
-
85% 成功率
Verify file exists: print(list((Path(__file__).parent/'templates').iterdir()))
无效尝试
常见但无效的做法:
-
40% 失败
Trailing slash can cause double-slash path issues in some versions.
-
60% 失败
Breaks deployment layout and packaging.