来自查询的值在 Jinja 中显示为元组,但应该是单个字符串
Value from query shows up as tuple in Jinja, but should be single string
我有一个 mysql 查询,我试图将其显示为字符串,但现在我得到一个仅包含该字符串的元组。为什么 return 不是我要求的专栏?如何只获取字符串?
kitchen_locations = <mysql select query>
# get
('myquery',)
# want
myquery
{% for kitchen_location in kitchen_locations: %}
<li><a href="/{{kitchen_location}}/">{{kitchen_location}}</a></li>
<br/>
{% endfor %}
你查询returns一个元组,即使你只有select一个字段。当您将元组转换为字符串时,您会得到括号和逗号。要获得所需的值,请指定元组中的第一项。
<li><a href="/{{kitchen_location[0]}}/">{{kitchen_location[0]}}</a></li>
我有一个 mysql 查询,我试图将其显示为字符串,但现在我得到一个仅包含该字符串的元组。为什么 return 不是我要求的专栏?如何只获取字符串?
kitchen_locations = <mysql select query>
# get
('myquery',)
# want
myquery
{% for kitchen_location in kitchen_locations: %}
<li><a href="/{{kitchen_location}}/">{{kitchen_location}}</a></li>
<br/>
{% endfor %}
你查询returns一个元组,即使你只有select一个字段。当您将元组转换为字符串时,您会得到括号和逗号。要获得所需的值,请指定元组中的第一项。
<li><a href="/{{kitchen_location[0]}}/">{{kitchen_location[0]}}</a></li>