【发布时间】:2017-04-11 21:37:13
【问题描述】:
在我正在处理的 Flask 函数的 GET 部分中,我有一些用 Python 3 编写的非常简单的代码。我试图传入的数据永远不会显示在我的 HTML 渲染中。
@app.route("/sellselected", methods=["GET", "POST"])
@login_required
def sellselected(order_num):
if request.method == "POST":
#not done, just have a redirect to index
else:
stock_to_sell = db.execute("SELECT * FROM purchases WHERE order_num = :order_num", order_num=order_num)
#stock_to_sell = ['fish']
return render_template("sellselected.html", stock_to_sell=stock_to_sell, order_num=order_num)
SQL 语句似乎没有传递任何内容,它在 HTML 渲染中只是空白。但作为测试,我也使用了“鱼”,它也是无/空的。
神社的样子:
{% block main %}
<list>
<ul>{{ stock_to_sell }}</ul>
<ul>{{ order_num }}</ul>
</list>
{% endblock %}
所以页面正文有订单号,但是 stock_to_sell 始终为空。
【问题讨论】:
-
你正在传递一个列表;这是你的意图吗?如果你只通过
'fish'会发生什么? -
是的,jinja 使用 for 和列表更复杂,但我简化了直到我可以让 stock_to_sell 渲染。 'fish' 也不起作用。
标签: python sql python-3.x flask jinja2