I'm having problems printing contents of SQLite database into a Flask web page.
The output of the code below does not return the records I have fetched from the database into the Flask web page which is expecting it, and will display into a table.
The code I have so far:
flask.py
from flask import Flask
from flask import render_template
import sqlite3
conn = sqlite3.connect('sqlite_test.db') c = conn.cursor()
app = Flask(__name__)
@app.route('/') def index():
c.execute('SELECT * FROM facebook_posts')
return render_template('flask.html', rows = c.fetchall())
if __name__ == '__main__':
app.run()
flask.html
<table class="table table-hover">
<thead>
<tr>
<th>StatusID</th>
<th>Status Message</th>
<th>Link</th>
<th>Status Type</th>
<th>Status Link</th>
<th>Status Published</th>
<th>Reaction Count</th>
<th>Comment Count</th>
<th>Share Count</th>
<th>Like Count</th>
<th>Love Count</th>
<th>Wow Count</th>
<th>Haha Count</th>
<th>Sad Count</th>
<th>Angry Count</th>
</tr>
</thead>
<tbody>
{% for row in rows %}
<tr>
<td>{{status_id}}</td>
<td>{{status_message}}</td>
<td>{{link_name}}</td>
<td>{{status_type}}</td>
<td>{{status_link}}</td>
<td>{{status_published}}</td>
<td>{{num_reactions}}</td>
<td>{{num_comments}}</td>
<td>{{num_shares}}</td>
<td>{{num_likes}}</td>
<td>{{num_loves}}</td>
<td>{{num_wows}}</td>
<td>{{num_hahas}}</td>
<td>{{num_sads}}</td>
<td>{{num_angrys}}</td>
</tr>
{% endfor %}
</tbody>
</table>
Am I missing something or might have overlooked?
flask.htmland you are usingindex.html.