
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 %}
为什么页面查看源码搜这样的
<li><h2></h2>
<li><h2></h2> <li><h2></h2> <li><h2></h2> <li><h2></h2> <li><h2></h2> <li><h2></h2> <li><h2></h2> 也就是说 字段没有显示,但是 列数是对的。我明明写的是 select * from
1 lilydjwg 2015-06-03 21:58:42 +08:00 因为 entry 没有那些属性。神奇的 jinja2 会在这种情况下将之渲染成空字符串。 entry 是从数据库里取到的。默认是 tuple 类型,如果使用 DictCursor 的话会是字典类型。除非你自己写个 cursor 类,否则无论如何不会是 ORM 那样的带属性的对象。 |
3 lilydjwg 2015-06-03 22:52:55 +08:00 @hiboshi 我不太了解 jinja2。用过 ORM。 也许 jinja2 能自动把属性访问变换成取字典键值?你试试 DictCursor,MySQLdb 应该有。 |
5 itommy 2015-06-03 23:11:41 +08:00 |
7 hiboshi OP |
8 sivacohan PRO 你看一下你这么connect好像是没有连接池的吧? 建议外面包个连接池 |