数据表python flas

2024-03-29 07:46:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个关于mysql db python表的问题。你知道吗

我的问题是我的数据没有显示在表中。我可以看到它得到了数据,因为当我在mysql数据库中添加数据行时,表会增加。你知道吗

你知道吗应用程序类型代码:

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

Tags: 数据testdatareturnhtmlmysqltabletemplate