I used IBM DB2 and Flask. when I start retrieving data through flask and it displaying vertically. {it shows the data[lycra is a single word] verically}
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{% for NAME in dictionary %}
<tr>
<td><li>{{NAME}}</li></td>
</tr>
{% endfor %}
</tbody>
</table>
@app.route("/home")
def display():
sql = "SELECT * FROM SHIRT"
stmt = ibm_db.exec_immediate(conn, sql)
#dictionary = ibm_db.fetch_row(stmt)
result=ibm_db.result(stmt,"NAME")
print(result)
return render_template('testing.html',dictionary=result)
where did I need to correct my code to display the data horizontally
CodePudding user response:
Close tr tag at out of the loop
Or you just ommit the closing /tr tags Because the the browser automatically close the tr tags when new tr is open or end of the web page
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{% for NAME in dictionary %}
<tr>
<td><li>{{NAME}}</li></td>
{% endfor %}
</tr>
</tbody>
</table>
@app.route("/home")
def display():
sql = "SELECT * FROM SHIRT"
stmt = ibm_db.exec_immediate(conn, sql)
#dictionary = ibm_db.fetch_row(stmt)
result=ibm_db.result(stmt,"NAME")
print(result)
return render_template('testing.html',dictionary=result)
CodePudding user response:
Try printing just the dictionary in HTMl without any loop.