【BUG】jinja2.exceptions.TemplateNotFound

这段时间,陆陆续续在做一些开发,记录下,这个该死的bug,把人反反复复折磨了1个小时,最终以一种意想不到的方式解决了它。

任务:设置后端服务器,我创建一个server.py,用于设置 Flask 服务器,并加载 ONNX 模型。前端也由test.html写好了。然后运行......

python 复制代码
# 定义了路由和展示的页面
@app.route('/')
def template():
    return render_template('./html/test.html')

此时我的工程目录是这样的,路径和文件名都没问题,简直怀疑人生。

python 复制代码
----project
    ----server.py
    ----html
        ----test.html

好,这样不行,那我就换成绝对地址,这样就不受目录的限制,然后依旧报错。

解决方案

最后,翻看了一些大家遇到这个问题的记录,修改后,我的工程目录是这样的

python 复制代码
----project
    ----server.py
    ----templates
        ----test.html

然后!!!!!就好了!!!!!!!!太离谱了!!!!!!存放html文件的文件夹名字必须是"templates"!!!!!!!

修改后就可以正常运行了。

相关推荐
phantom_1112 天前
Cursor 分析 bug 记录
bug·cursor
Direction_Wind4 天前
Flinksql bug: Heartbeat of TaskManager with id container_XXX timed out.
大数据·flink·bug
AIBigModel6 天前
智能情趣设备、爆 bug:可被远程操控。。。
网络·安全·bug
Direction_Wind6 天前
flinksql bug: Received resultset tuples, but no field str
bug
远瞻。7 天前
【bug】diff-gaussian-rasterization Windows下编译 bug 解决
windows·bug
中草药z7 天前
【测试】Bug+设计测试用例
功能测试·测试工具·测试用例·bug·压力测试·测试
我又来搬代码了7 天前
【Android】【bug】Json解析错误Expected BEGIN_OBJECT but was STRING...
android·json·bug
葵野寺8 天前
【软件测试】BUG篇 — 详解
bug·测试
青青子衿越10 天前
微信小程序右上角分享页面找不到路径bug
微信小程序·小程序·bug
刘火锅10 天前
Bug 记录:SecureRandom.getInstanceStrong()导致验证码获取阻塞
spring boot·spring·spring cloud·bug