python config_error ai_generated true

jinja2.exceptions.TemplateNotFound: index.html

ID: python/flask-jinja2-template-not-found

其他格式: JSON · Markdown 中文 · English
80%修复率
89%置信度
0证据数
2024-05-19首次发现

版本兼容性

版本状态引入弃用备注
2.x active — — —
3.x active — — —

根因分析

模板文件不在应用根目录下的 `templates/` 目录中,或应用以错误的 `root_path` 创建。

English

The template file is not in the configured `templates/` folder relative to the app root, or the app was created with the wrong `root_path`.

generic

解决方案

  1. 97% 成功率
    project/
      app.py
      templates/index.html
    app = Flask(__name__, template_folder='templates')
  2. 85% 成功率
    app.jinja_loader.searchpath.append('/abs/path/templates')

无效尝试

常见但无效的做法:

  1. 70% 失败

    Bypasses loader but loses autoescape/extends; brittle path handling.

  2. 90% 失败

    Reload flag only affects change detection, not lookup.