Reputation: 119
I have a sqlite db and the data is in the format - ('value','timestamp'). I am using a html file to render the data on a flask application eventually.
index.html is as follows -
<!DOCTYPE html>
<html>
<head>
<title>{{ title }} - XYZ</title>
</head>
<body>
<h1>Page for Information</h1>
<p style="color:blue;"></p>
<table style="width:100%">
{% for row in data%}
<tr>
<td> {{ row }} </td>
</tr>
{% endfor %}
<tr>
</table>
</body>
</html>
Right now the flask app prints like this which is unstructured :
('17 days', '2018-11-30 13:52:55') ('17 days', '2018-11-30 13:53:42')
DO I need to split/remove parantheses/single quotes before passing to the html?
Upvotes: 0
Views: 692
Reputation: 373
You can access the variables of the row individually (I've comma separated the 2 values but you can just leave a space):
<th>Value</th>
<th>Timestamp</th>
{% for row in data %}
<tr>
<td>{{ row[0] }}</td> <td>{{ row[1] }}</td>
</tr>
{% endfor %}
Should give you:
17 days, 2018-11-30 13:52:55
17 days, 2018-11-30 13:53:42
If they are named values use:
{{ row.value }}, {{ row.timestamp }}
Upvotes: 1