Cannot get HTML to display SQLite3 data with python & flask
<p>I'm having an issue getting an HTML page to display my SQLite3 data using Python &amp; Flask. I found a question on here and used the same code, plus different variations to no success. There are no error messages and the HTML page loads, however there is no data present. This is the code I am using to get the data;</p>

<pre><code>@app.route("/viewpackages", methods=['GET'])
def viewpackages():
    con = sqlite3.connect('utpg.db')
    db = con.cursor()
    user_id = session.get('id')
    getpackages = db.execute("SELECT pck_id, client_id, date, price,  privatelesson,"
                             "shortgamelesson, playinglesson, notes FROM packages WHERE client_id = ?;", (user_id, ))

    return render_template("view_packages.html", items=getpackages.fetchall())
</code></pre>

<p>this is the code I attempting to use to display the data;</p>

<pre class="lang-html prettyprint-override"><code>&lt;table&gt;
{% for item in items %}
&lt;tr&gt;
    &lt;td&gt;{{column1}}&lt;/td&gt;
    &lt;td&gt;{{column2}}&lt;/td&gt;
    &lt;td&gt;{{column3}}&lt;/td&gt;
    &lt;td&gt;{{column4}}&lt;/td&gt;
    &lt;td&gt;{{column5}}&lt;/td&gt;
    &lt;td&gt;{{column6}}&lt;/td&gt;
    &lt;td&gt;{{column7}}&lt;/td&gt;
    &lt;td&gt;{{column8}}&lt;/td&gt;
&lt;/tr&gt;
{% endfor %}
&lt;/table&gt;
</code></pre>

<p>I tried changing 'column' to the actual db column name, with the same issue. I tried calling SELECT * instead of each individual column, same issue. If I run this code in python;</p>

<pre><code>con = sqlite3.connect('utpg.db')
db = con.cursor()
user_id = session.get('id')
getpackages = db.execute("SELECT pck_id, client_id, date, price,    privatelesson, shortgamelesson, playinglesson, notes FROM   packages WHERE        client_id = ?;", (user_id, ))
packages = getpackages.fetchall()
for row in packages:
     print(row)
</code></pre>

<p>It returns the desired results. So I am thinking there is an issue with the HTML somewhere but I cannot figure it out.</p>

<p>Please try the following code and let me know if it works for you:</p>

<pre><code>&lt;table&gt;
{% for item in items %}
&lt;tr&gt;
    &lt;td&gt;{{ item[0] }}&lt;/td&gt;
    &lt;td&gt;{{ item[1] }}&lt;/td&gt;
    &lt;td&gt;{{ item[2] }}&lt;/td&gt;
    &lt;td&gt;{{ item[3] }}&lt;/td&gt;
    &lt;td&gt;{{ item[4] }}&lt;/td&gt;
    &lt;td&gt;{{ item[5] }}&lt;/td&gt;
    &lt;td&gt;{{ item[6] }}&lt;/td&gt;
    &lt;td&gt;{{ item[7] }}&lt;/td&gt;
&lt;/tr&gt;
{% endfor %}
&lt;/table&gt;
</code></pre>

<p><strong>Test with the following code:</strong></p>

<p><strong><em>app.py</em></strong></p>

<pre><code>from flask import Flask, render_template
import sqlite3

app = Flask(__name__)
app.secret_key = 'development key'


@app.route('/users')
def get_users():
    con = sqlite3.connect('mydb.db')
    db = con.cursor()
    db.execute('insert into user values ("Aaa", "AAA")')
    db.execute('insert into user values ("Bbb", "BBB")')
    res = db.execute('select * from user')
    return render_template('users.html', users=res.fetchall())

if __name__ == "__main__":
    app.run(host="0.0.0.0", debug=True)
</code></pre>

<p><strong><em>templates/users.html</em></strong></p>

<pre><code>&lt;html !DOCTYPE&gt;
&lt;head&gt;
&lt;title&gt;SQLite&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table&gt;
{% for user in users %}
&lt;tr&gt;
    &lt;td&gt;{{ user[0] }}&lt;/td&gt;
    &lt;td&gt;{{ user[1] }}&lt;/td&gt;
&lt;/tr&gt;
{% endfor %}
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

python html flask sqlite3 jinja2