这是我的模板
{% for item in naa %}
<a href="post/{{item['id']}}/{{item['about']}}">{{item['about']}}</a>
{% endfor %}
和烧瓶:
cur.execute("SELECT post_id FROM favorites WHERE username = %s",[session['username']])
data=cur.fetchall()
naa = []
for row in data:
pos_id = row["post_id"]
cur.execute("SELECT* FROM posts WHERE id=%s ORDER BY created_at DESC",[pos_id])
naa.append(cur.fetchall())
cur.close()
return render_template("favoritesm.html",naa = naa)
它显示结果,但链接断开,如:
localhost/post//
那有什么问题以及如何解决?
谢谢
答案 0 :(得分:0)
.fetchall()返回一个list of tuples。因此,.append将创建一个列表列表。我相信您想改用.extend。
naa.extend(cur.fetchall())
请参见the answer至What is the difference between Python's list methods append and extend?