【发布时间】:2020-09-15 13:14:21
【问题描述】:
{{ form.product.label }}
<select name="{{ form.product.name }}" id="product">
{% for product in products %}
<option value="{{product.name}}">{{product.name}}</option>
{% endfor %}
</select>
我试图让用户从产品表中的名称中选择一个值并将其存储在另一个表中,但下拉列表是空的,而它应该有五个选项。
movements = Movement.query.all()
products = Product.query.all()
locations = Location.query.all()
return render_template('movements.html', movements=movements, products=products, locations=locations, form=form)
【问题讨论】:
-
你还没有告诉我们什么是行不通的。你得到了什么输出?
-
下拉列表是空的,它应该有五个选项。
-
您确定从您的产品查询中收到任何信息吗?
-
当我检查页面源代码时,选择标签中没有任何内容,所以我认为我不是,但我不知道为什么不这样做,因为我在另一个中使用了相同的 for 循环程序的一部分(打印值,而不是创建列表),并且有效。
-
无论
products变量是否为空,您是否尝试过在路由函数中调试它?
标签: html flask sqlalchemy