python - 数据表 python flask

标签 python mysql flask

我对 Bootstrap 中的 mysql db python 表有疑问。

我的问题是我的数据没有显示在表格中。我可以看到它获取数据,因为当我在 mysql 数据库中添加带有数据的行时,表会增加。

app.py代码:

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

最佳答案

代替

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

这样做

  <td>{{test[0]}}</td>
  <td>{{test[1]}}</td>

关于python - 数据表 python flask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52425073/

相关文章:

mysql - 动态表单字段验证的数据库设计

php - 用户在 php 中的动态表单?

python - 由图像制成的按钮 - Tkinter

python - 将 South Migrations 添加到第 3 方 Django 应用程序

python - Django 分页泛型 LISTCREATEAPIview 中的条件查询集

mysql - SQL 子查询不起作用

python - 我可以使用 Flask 在 URL 中添加可选的 URL 描述吗?

python - Flask应用未在本地主机上正确显示

python - 如何检查 SqlAlchemy 中的查询是否返回空结果?

python - 数组校验和算法 - Python 3