flask查询返回字典类型

import MySQLdb
conn=MySQLdb.connect(host="localhost",user="root",passwd="",db="web")
cursor = conn.cursor()
cursor.execute("select * from `weather`")
entries = cursor.fetchall()
return render_template('test.html', entries=entries)

import MySQLdb
import MySQLdb.cursors
conn=MySQLdb.connect(host="localhost",user="root",passwd="",db="web",cursorclass=MySQLdb.cursors.DictCursor)
cursor = conn.cursor()
cursor.execute("select * from `weather`")
entries = cursor.fetchall()
return render_template('test.html', entries=entries)

{% for entry in entries %}
    <li><h2>{{ entry.id }}</h2>{{ entry.dara_from }}
{% else %}
    <li><em>Unbelievable.  No entries here so far</em>
{% endfor %}

此条目发表在笔记分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注