【发布时间】:2017-08-01 16:26:39
【问题描述】:
我在烧瓶应用程序中运行两个脚本,结果不同。 第一个以字符串形式返回数据库值:
for row in cursor.execute("SELECT tweet,sentiment FROM thistable
WHERE sentiment > 70 AND +keyword=? ORDER BY sentiment DESC", (query,)):
bestlist.append(row)
HTML:
{% for tweet, sentiment in bestlist %}
<h3>{{ tweet }}</h3>>
<h5>Score : {{ sentiment }}</h5>
{% endfor %}
输出
Lorem ipsum dolor sit
Score : 94.9
Ameat valc simon chaq
Score : 88.2
第二个我只从列表中获取一个值:
for row in cursor.execute("SELECT DISTINCT keyword FROM thistable"):
last_keys.append(row)
HTML:
{% for row in last_keys %}
<h3>{{ row }}</h3>
{% endfor %}
同样的事情..
{% for keyword in last_keys %}
<h3>{{ keyword}}</h3>
{% endfor %}
输出:
(u'Nasdaq',)
(u'Russia',)
(u'Samsung',)
我正在寻找的是这样的:
Nasdaq
Russia
Samsung
谢谢!
【问题讨论】: