python config_error ai_generated true

jinja2.exceptions.TemplateNotFound: index.html

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.9 active
3.10 active

Root Cause

Flask 在默认模板目录 'templates' 中找不到指定的模板文件

generic

中文

Flask 在默认模板目录 'templates' 中找不到指定的模板文件

Workarounds

  1. 95% success 创建 templates 文件夹并放置模板文件
    mkdir templates && mv index.html templates/
  2. 90% success 在 Flask 应用中自定义模板目录
    app = Flask(__name__, template_folder='custom_templates')

Dead Ends

Common approaches that don't work:

  1. 将模板文件放在项目根目录而非 templates 文件夹 80% fail

    Flask 默认只搜索 templates 文件夹

  2. 修改模板路径为绝对路径但忘记更新 render_template 调用 60% fail

    路径不匹配或权限问题