<sqlite3.Row object at 0x1017fe3f0> instead of database contents

flask, python, sqlite

Solution

You need to get the data from the rows:

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

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

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 %}

Problem

My templates is this: ``` {% 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?

Original source