Python fetchall方法获取tuple转到form表单逐条显示如何实现,fetchalltuple,python中用fetc


python中用fetchall在数据中获得了一个tuple,请问怎么转到form表单中逐条显示呢?x谢谢。
form中同栏只有一个name,用如下代码传给form只能显示单条。

pythoncur.execute("SELECT title,sh_url FROM test")contents = cur.fetchall()    for row in contents:        title=row[0]        sh_url=row[1]    return render_template('list.html',title=title,sh_url=sh_url)

建议用列表表达式
cur.execute("SELECT title,sh_url FROM test")
articles = ((row[0], row[1]) for row in cursor.fetchall())
return render_template('list.html', {‘articles’: articles}

可以这样迭代数组
for title, url in articles
print ‘

{0}{1}

编橙之家文章,

评论关闭