模板
1,在渲染模板时,默认会从项目根目录 下 ‘templates’ 目录下查找
2,如果不想把模板文件放在templates 目录下,那么可以在 falsk
template_folder 设置路径
模板参数笔记
1,在使用render_template 渲染模板时,可以传递参数 ,以后直接在模板中使用就可以了
2,如果你的参数过多,可以将所有的参数放在一个,然后在传字典参数时,使用**
将字典打散成关键字参数
context = {
‘username’:‘eagle’,
‘age’:18,
‘country’:‘china’,
‘children’:{
‘height’:100,
‘weight’:10
}
}
# **context 把字典转换成关键子键值对
return render_template(‘index.html’,**context)
模板中的url_for 跟我们后台视图函数中的url_for 使用基本一样
也是传递视图的名字,也可以传递参数
登录