Python Flask报错:raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound

本文内容皆为作者原创,如需转载,请注明出处:https://www.cnblogs.com/temari/p/13178903.html

遇到问题:

Python引入Flask,脚本运行时报错"raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound",如图:

问题解决

Flask应用一般在templates文件夹中查找HTML文件,且templates文件夹要与运行py文件在同一层级。报错的原因是没有创建templates文件目录。

选中project,右键点击New->Directory,录入templates,回车,如图:

创建成功后选中templates,右键新建html文件。重新运行程序即可。如图:

在浏览器中访问接口,页面显示正常,如图:

猜你喜欢

转载自www.cnblogs.com/temari/p/13178903.html