python 2.7 - Creating a bootstrap table with data from MySQLdb in flask -
hello guys trying create bootstrap table data mysql database. getting error local variable data referenced before assignment. please code 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 * 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 not working hoping on getting value [0] , [1] tuple( data= c.fetchall()) table error local variable 'data' referenced before assignment.but if change return render_template("view.html", data=data) return render_template("view.html") runs no error empty noting print. there better way or missing something. please advice or help. link code are. http://pastebin.com/u/itetteh/1 thanks
Comments
Post a Comment