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>
1

1 Answer 1

1

instead of

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

do this

  <td>{{test[0]}}</td>
  <td>{{test[1]}}</td>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.