< sqlite3.Row对象位于0x1017fe3f0>代替数据库内容 [英] <sqlite3.Row object at 0x1017fe3f0> instead of database contents

查看:36
本文介绍了< sqlite3.Row对象位于0x1017fe3f0>代替数据库内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模板是这样的:

  {% for order in orders %}
    <li><h2>{{ order}}</h2>
  {% endfor %}

我的路由功能是这样的:

and my routing function is this:

@app.route('/order_history')
def orderhistory():
    db = get_db()
    cur = db.execute('select * from order_items')
    orders = cur.fetchall()
    return render_template('order_history.html', orders = orders)

知道我为什么要获得行对象位置而不是数据库内容吗?

Any idea why I am getting row object locations instead of the db contents?

推荐答案

您需要从行中获取数据:

You need to get the data from the rows:

{% for order in orders %}
  <li><h2>{{ order[0] }}</h2></li>
{% endfor %}

SQL查询总是返回包含列的行中的数据.以上假设您的 SELECT 每行仅返回一列.

A SQL query always returns data in rows, containing columns. The above assumes your SELECT returned just one column per row.

如果您有多列,则必须使用直接索引( order [1] order [3] 等)来解决这些问题或循环在行上显示列:

If you have multiple columns, you'd have to either address these with direct indices (order[1], order[3], etc.) or loop over the row to show the columns:

{% for order in orders %}
  <li><h2>{{ order[0] }}</h2>
      {% for column in order %}
          {% if not loop.first %}{{ column }}<br />{% endif %}
      {% endfor %}
  </li>
{% endfor %}

这篇关于&lt; sqlite3.Row对象位于0x1017fe3f0&gt;代替数据库内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆