hello guys I am trying to create a bootstrap table with data from MySQL database. I am getting an error local variable data referenced before assignment. Please help my code is as below.
app.py code
@app.route("/viewSingle", methods=['POST','GET'])
def SingleView():
if request.method=="POST":
if request.form['submit']=="View CONTINENT":
c,conn = connection()
c.execute('''select * from Country''')
data = c.fetchall ()
c.close ()
conn.close ()
return render_template("view.html",data=data)
view.html
<div class = "one1-div">
<div class ="container">
<form class="form-group" action="{{ url_for('SingleView') }}" method=post>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{%for row in data%}
<tr class="success">
<td>{{row[0]}}</td>
<td>{{row[1]}}</td>
<td>{{row[2}}</td>
</tr>
{%endfor%}
</tbody>
</table>
</form>
It seems to not be working I was hoping on getting the value [0] and [1] from the tuple( data= c.fetchall()) into the table but I get the error local variable 'data' referenced before assignment.But if I change the return render_template("view.html", data=data) to he return render_template("view.html") its runs with no error but just that the is empty noting print. Is there a better way to do this or am I missing something. Please advice or help. This is the link to where the code are. http://pastebin.com/u/itetteh/1 thanks