一、模版的放置位置

常规情况下是在app的根目前 创建 templates文件夹,然后放入html文件

使用url访问 http://0.0.0.0:5000/templates/lucax.html 就可以访问成功

 

和访问静态文件一样,也有 设置静态文件路径、和 访问静态文件url的参数设置

app = Flask(__name__,template_folder="/lucax",template_url_path='/uuu')

 

当需要把 templates文件夹移入蓝图下,也只要修改蓝图的 参数(注意相对路径,蓝图的根目前和应该的有区别)

web=Blueprint("web",__name__,template_folder="/lucax",template_url_path='/uuu')

 

二、视图函数访问模版 使用 render_template函数

@web.route("/test")

def test():
  r={

  '

]  

render_template('test.html',data=r,data2=r2)  ,200 指定响应代码

 

test.html 模版内引用参数变量的方法,获取变量是 2个花括号{{ }}

这里使用的是jianja2的语法去渲染,见jianjia2官网 or

参考下 

https://www.jianshu.com/p/83f5c3fd264c

https://www.cnblogs.com/kaibindirver/p/12869496.html

<body>
刘大兵 年龄 {{data2[0]}}   #访问数组
</br>
刘大兵 年龄 {{data.age}}  #访问字典
</body>

相关文章:

  • 2021-12-04
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2022-01-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-11
  • 2021-11-12
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
相关资源
相似解决方案