zoukankan      html  css  js  c++  java
  • 003:Python flask引入jinja2.exceptions.TemplateNotFound出错

    代码

     1 #_*_coding:utf-8_*_
     2 from flask import Flask
     3 from flask import render_template
     4 app=Flask(__name__)
     5 @app.route('/hello')
     6 @app.route('/hello/<name>')
     7 def hello(name=None):
     8     return render_template('hello.html',name=name)
     9 
    10 if __name__ == '__main__':
    11     app.run(port=5001,debug=True,host='0.0.0.0')

    hello.html

     1 <!doctype html>
     2 
     3 <title>Hello Sample</title>
     4 
     5 {% if name %}
     6 
     7   <h1>Hello {{ name }}!</h1>
     8 
     9 {% else %}
    10 
    11   <h1>Hello World!</h1>
    12 
    13 {%  endif  %}

    使用python flask框架报错TemplateNotFound: hello.html

    这种错误都是templates文件夹放错位置,将此templates文件夹放置在运行程序的文件夹中,就是说templates文件夹和运行文件位于同一级。

    运行结果

  • 相关阅读:
    Flutter页面-基础Widget
    Data 方法、异常与类
    kafka手动设置offset
    centos 安装ftp服务BUG
    定时任务
    Java垃圾收集算法
    ByteBuffer数据结构
    HelloWorldDynamic
    HelloWorld
    sql技巧(增册改查)
  • 原文地址:https://www.cnblogs.com/lisa2016/p/12202667.html
Copyright © 2011-2022 走看看