python config_error ai_generated true

jinja2.exceptions.TemplateNotFound: 未找到模板index.html

jinja2.exceptions.TemplateNotFound: index.html

ID: python/flask-template-not-found

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 95% 成功率
    app = Flask(__name__, template_folder='templates')
  2. 92% 成功率
    import os\napp = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), 'templates'))

无效尝试

常见但无效的做法:

  1. 90% 失败

    Reload flag only affects caching, not missing files.

  2. 50% 失败

    Works but bypasses template inheritance and is unmaintainable.