繁体   English   中英

将 SQLite3 数据库中的查询显示到 Bootstrap 表中

[英]Display Query from SQLite3 Database into Bootstrap table

我想将我的查询从 SQLite3 显示到 Bootstrap 表中。 但它似乎不起作用并且不会显示表格。 附上我的代码

视图.py

@main.route('/currentlist', methods=["GET"])
def current():
    if request.method == 'GET':
        Connection = sqlite3.connect('C:\\Backup_old\\Task\\e_ticket\\my_app\\db\\customer.db')
        cursor = Connection.cursor()
        query2 = "SELECT * from customer"
        cursor.execute(query2)
        test = cursor.fetchall()
        return render_template('overview.html', testform = test)

HTML

<div class= "content">

      <table id="dtBasicExample" class="table" width="100%">
        <thead>
          <tr>
            <th class="th-sm">Date
            </th>
            <th class="th-sm">time
            <th class="th-sm">customer
            </th>
            <th class="th-sm">pic
            </th>
            <th class="th-sm">category
            </th>
            <th class="th-sm">description
            </th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>9 December 2021</td>
            <td>15:30:00</td>
            <td>AB Corp.</td>
            <td>Bob</td>
            <td>network</td>
            <td>network is down</td>
          </tr>
          <tr>
            <td>9 December 2021</td>
            <td>17:30:00</td>
            <td>AB Corp.</td>
            <td>Alex</td>
            <td>computer</td>
            <td>computer is broken</td>
          </tr>
          <tr>
            <td>10 December 2021</td>
            <td>05:32:00</td>
            <td>CD Corp.</td>
            <td>Bob</td>
            <td>Server</td>
            <td>server is down</td>
          </tr>
          <tr>
            <td>12 December 2021</td>
            <td>10:30:00</td>
            <td>AB Corp.</td>
            <td>Bob</td>
            <td>printer</td>
            <td>printer is down</td>
          </tr>


        </tbody>
        
      </table>
    



    </div>

它应该是这样的,但使用数据库中的数据在此处输入图像描述

我读过很多类似的问题,但大多数都使用 SQLAlchemy。

非常感谢任何帮助!

您需要对数据使用循环和模板变量。

<tbody>
  {% for row in testform %}
  <tr>
    <td>{{ row[0] }}</td>
    <td>{{ row[1] }}</td>
    <td>{{ row[2] }}</td>
    <td>{{ row[3] }}</td>
    <td>{{ row[4] }}</td>
    <td>{{ row[5] }}</td>
  </tr>
  {% endfor %}
</tbody>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM