一 *** 关于宏的函数声明和调用

app.py
#宏 mscro 函数( 参数){{ 参数 }} 进行调用来显示数据
@app.route('/show')
def show():
movies=['夺冠 改编自《中国女排》','我和我的家乡','妖猫传']
return render_template('index.html',movies=movies)



二 **** locals用法
app.py
from flaskimport Flask,render_template,request
app=Flask(__name__)
@app.route('/')
def index():
book_name='《钢铁是怎么炼成的》'
book_author='奥斯特洛夫斯基'
book_price='56'
book_public='北京大学出版社'
print(locals())
dict={
"name":'《少年的你》',
'producer':"曾国祥",
'price':55,
'publisher':'北京电影制片厂'
}
list=['中餐厅','认真的嘎嘎们','中国新说唱','少年之名','忘不了餐厅','奔跑吧兄弟','极限挑战','明日之子 乐团季','这就是街舞','妻子的浪漫旅行']
tup=('乘风破浪的姐姐','青春有你','说唱听我的','创造营','中国新说唱','少年之名','明日之子 乐团季','这就是街舞')
#locals()是将当前的变量内容转化为字典格式
return render_template('book.html',params=locals())


三 **** 变量的过滤器
app.py



四 **** 逻辑控制语句展示
app.py



五 **** 父类子类模板继承
app.py

parent.html
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>父模板
<h1>父模板的头部信息
{%block container %}
<h1>父模板的主体信息
{%endblock %}
<h1>父模板的底部信息
</html>
child.html
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>子模板
<h1>继承自父类模板,减少重复性的代码,代码更加简洁
{%extends 'parent.html' %}
{%block container %}
{{super() }}
<h3>父类模板中的主体内容被代替
{%endblock %}
</html>


网友评论