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

遇到问题:

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

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

问题解决

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

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

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

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

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

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

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

相关文章:

  • 2021-06-12
  • 2021-08-14
  • 2022-01-09
  • 2022-12-23
  • 2021-08-22
  • 2021-09-16
  • 2021-08-22
猜你喜欢
  • 2022-12-23
  • 2021-11-21
  • 2021-09-27
  • 2021-10-06
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
相关资源
相似解决方案