python config_error ai_generated true

jinja2.exceptions.TemplateNotFound: index.html

ID: python/starlette-template-not-found

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-04-21First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

Jinja2Templates directory does not contain the template, or the directory path is wrong relative to the working directory.

generic

中文

Jinja2Templates 目录不包含该模板,或目录路径相对于工作目录错误。

Workarounds

  1. 93% success
    templates = Jinja2Templates(directory=Path(__file__).parent / 'templates')
  2. 85% success
    Verify file exists: print(list((Path(__file__).parent/'templates').iterdir()))

Dead Ends

Common approaches that don't work:

  1. 40% fail

    Trailing slash can cause double-slash path issues in some versions.

  2. 60% fail

    Breaks deployment layout and packaging.