HTML:
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 hello 9 <br> 10 {{ data }} 11 {{ data['name'] }} 12 {{ data.name }} 13 <br> 14 mylist:{{ data.mylist }} 15 <br> 16 mylist[1]:{{ data.mylist[1] }} 17 <br> 18 count:{{ data.mylist[1]+data.mylist[2] }} 19 <br> 20 {{ 'hello_world' | upper}} 21 <br> 22 {{ 'hello_world' | title}} 23 <br> 24 {{ 'hello_world' | replace('hello', 'hi')}} 25 </body> 26 </html>
Python:
1 #模板 jinjia2 2 from flask import Flask,render_template 3 4 app = Flask(__name__) 5 6 @app.route('/index') 7 def index(): 8 data = { 9 'name':'张三', 10 'age':18, 11 'mylist':[1,2,3,4,5,6] 12 } 13 return render_template('index2.html', data=data) #后者字典给了前者变量 14 15 if __name__ == '__main__': 16 app.run()
标签:__,mylist,name,flask,app,过滤器,data,hello,模板 From: https://www.cnblogs.com/0xiaoyu/p/16593504.html