【发布时间】:2019-11-05 09:37:09
【问题描述】:
我正在使用表单向带有名称的模板发送响应。如何使用 jinja2 模板打印“路线”列表元素。下面我给出了我的 index.py 页面代码和所需的输出。请建议我应该在 jinja 模板中使用的代码以获得 expexted 输出。
@app.route('/route',methods=['GET','POST'])
def index():
form = Route()
if request.method == 'POST':
if form.validate_on_submit():
tnum = request.form["T_No"]
r = requests.get('https://api.railwayapi.com/v2/route/train/'+request.form['T_No']+'/apikey/<myapi>/').content
return render_template('showRoute.html',form=r)
return 'something wrong'
return render_template('route.html',form=form)
"route": [
{
"no": 1,
"scharr": "SOURCE",
"schdep": "06:15",
"distance": 0,
"halt": -1,
"day": 1,
"station": {
"name": "KALKA",
"code": "KLK",enter code here
"lng": null,
"lat": null
}
}
【问题讨论】: