我正在使用以下代码:
def static_info(nm):
cursor.execute("SELECT name,age,FROM MyDB where name like ?",(nm) + '%')
for row in cursor:
static={"NAME: ":row[0],"AGE: ":row[1]}
return(static)
@app.route('/submit_form')
def submit_form():
nm = request.form.get('name')
info=static_info(nm)
return render_template('static_display.html',info=info)
我的 static_display.html 页面上需要所需的函数输出(以字典的形式)
有什么建议么?
奇怪的编码。
您的循环static_info(nm)
只会返回最后一项。你没有附加任何东西
您@app.route('/submit_form')
不接受 POST。你需要:
@app.route('/submit_form', methods = ['GET', 'POST'])
在您的模板中static_display.html
,您需要{{ info }}
如果您更改代码以便可以遍历模板中的列表,您将需要以下内容:
{% for item in info %} {% for key, value in item.items() %}
{{ key }} : {{ value }}
{% endfor %} {% endfor %}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句