Reputation: 73
I am using a SQLite3 db file to retrieve data and store it in a variable so that I can use it to display the results on a HTML table.
This is how I am storing the results from the query:
test = c.execute("SELECT column_name from table_name LIMIT 11")
However, when I try to display it in the table, using "{%for x in test%}"
, the output is being displayed like this: (1.234,)
. What do I need to change for the output to look like this: 1.234
so without the bracket and comma?
Upvotes: 0
Views: 12998
Reputation: 1679
You want a list of all results of your query, you should use fetchall()
, which, according to the docs:
Fetches all (remaining) rows of a query result, returning a list. Note that the cursor’s arraysize attribute can affect the performance of this operation. An empty list is returned when no rows are available.
Try this:
c = sqlite3.connect('db_path.db')
cur = c.cursor()
cur.execute("SELECT column_name from table_name LIMIT 11")
test = cur.fetchall()
Your html would then look like this:
<table>
{% for row in test %}
<tr>
<th> {{ row[0] }}</th>
</tr>
{% endfor %}
</table>
Upvotes: 2