python config_error ai_generated true

jinja2.exceptions.TemplateNotFound: index.html

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-05-19First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2.x active — — —
3.x active — — —

Root Cause

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

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 70% fail

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

  2. 90% fail

    Reload flag only affects change detection, not lookup.