python config_error ai_generated true

模板未找到错误:index.html

jinja2.exceptions.TemplateNotFound: index.html

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

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

版本兼容性

版本状态引入弃用备注
3.9 active
3.10 active

根因分析

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

English

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

generic

解决方案

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

无效尝试

常见但无效的做法:

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

    Flask 默认只搜索 templates 文件夹

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

    路径不匹配或权限问题