from flask import Flask,redirect,render_template,jsonify,send_file,request,Markup,session
import json
from datetime import timedelta
app = Flask(__name__)
#模版支持get 点 索引[]方式获取值
def jinja22():
#模版支持get 点 索引[]方式获取值
name = [{'test':'dell','age':'222','city':'shh'}
,{'test':'HP','age':'22331','city':'2dad'}
,{'test':'haier','age':'122212','city':'fsadsa'}
,{'test':'shezhou','age':'99999','city':'sgfdsg'}
]
info = {
'1':{'test':'dell','age':'222','city':'shh'},
'2':{'test':'HP','age':'22331','city':'2dad'},
'3':{'test':'haier','age':'122212','city':'fsadsa'},
'4':{'test':'shezhou','age':'99999','city':'sgfdsg'},
}
inta = Markup("<input type='test'>")
return render_template("jinja2.html",msg = name, info=info,inta=inta,func=ab) #func函数计算
HTML中使用如下
{% for i in msg %}
{{ i.test }}---> {{ i.get('age') }}-->{{ i['city'] }} </br>
{% endfor %}
#可以单独获取第1条数据
{{msg.0.test}} ---> {{ msg.0.get('age') }}-->{{ msg.0['city'] }} </br>
{% for k,v in info.items() %}
<p>{{ k }} ---> {{ v }} ---> {{ v.test }}---->{{ v['age'] }}---->{{ v.get('city') }}</p>
{% endfor %}
{{ inta }}
{{ inta|safe }}