我们想要显示序号,可以通过loop.index来展示
这里我们想遍历一个复杂的列表字典,可以通过dict.items(),获取到字典的键和值
实现效果:
代码实现:
from flask import Flask,render_template
app = Flask(__name__)
student={
"name":"zhangsan ","age":17,"gender":"男",
}
student_list=[
{
"name":"zhangsan ","age":17,"gender":"男"},
{"name":"lisi ","age":25,"gender":"男"},
{"name":"wangwu ","age":69,"gender":"女"},
]
student_dict=[{
"aaa":{"name":"zhangsan ","age":17,"gender":"男"},
"bbb":{"name":"lisi ","age":25,"gender":"男"},
"ccc":{"name":"wangwu ","age":69,"gender":"女"}
}
]
@app.route('/test1')
def test1():
return render_template('1.html',**student)
@app.route('/test2')
def test2():
return render_template('2.html',stu_list=student_list)
@app.route('/test3')
def test3():
return render_template('3.html',stu_dict=student_dict)
if __name__ == '__main__':
app.run()
标签:语句,控制,name,render,复杂,student,gender,age,__ From: https://www.cnblogs.com/yongheng999/p/18311360