2

I have a question regarding mysql db python table in Bootstrap.

My question is my data is not shown in the table. I can see it gets data because of when I add row in mysql db with data the table increases.

app.py code:

@app.route('/dashboard')
@is_logged_in
def dashboard():
       #create cursor
    cur = mysql.get_db().cursor()
    #Get data
    result = cur.execute("SELECT * FROM test")
    data=cur.fetchall()
    if result > 0:
        return render_template('dashboard.html', data=data)
    else:
        msg = 'No DOC Found'
        return render_template('dashboard.html', msg=msg)
    #close connection
    cur.close()
    return render_template('dashboard.html' )

.html

  <table class="table table-striped">
              <tr>
                   <th>data1</th>
                   <th>data2</th>
              </tr>
              {% for test in data%}
              <tr>
                   <td>{{test.rdno}}</td>
                   <td>{{test.ipno}}</td>

                {% endfor %}
              </tr>
          </table>
van neilsen
  • 547
  • 8
  • 21
ABU
  • 107
  • 2
  • 3
  • 13
  • 1
    Have you checked this question for a possible solution: https://stackoverflow.com/questions/9845102/using-mysql-in-flask – Chuck LaPress Sep 20 '18 at 12:31

1 Answers1

1

instead of

<td>{{test.rdno}}</td>
<td>{{test.ipno}}</td>

do this

  <td>{{test[0]}}</td>
  <td>{{test[1]}}</td>
ABU
  • 107
  • 2
  • 3
  • 13