我有一个 mysql 查询,我试图将其显示为字符串,但现在我得到一个仅包含该字符串的元组。为什么它不只返回我要求的列?如何只获取字符串?
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 %}
最佳答案
即使您只选择一个字段,您的查询也会返回一个元组。当您将元组转换为字符串时,您会得到括号和逗号。要获取所需的值,请指定元组中的第一项。
<li><a href="/{{kitchen_location[0]}}/">{{kitchen_location[0]}}</a></li>
关于python - 查询的值在 Jinja 中显示为元组,但应该是单个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34942331/