首页 > 解决方案 > 模型中的引导表

问题描述

我有一个表,我正试图将静态模拟数据转换为真实的实时 SQLite3 数据。我希望在我的 HTML 代码中显示我的 SQLite3 表,包括我的所有三列(问题 | 答案 | Pub_Date),然后在表中显示值。

我当前的代码(如下)添加了问题列表,但它是将它们作为值从左到右而不是上下添加(下面的屏幕截图)。我需要调整什么来显示我的简单表格而不是假数据?

<table class="table table-hover">
  <thead>
    <tr style="font-family: Graphik Black; font-size: 14px">
      <th scope="col">#</th>
      <th scope="col">First</th>
      <th scope="col">Last</th>
    </tr>
  </thead>
  <tbody>
    <tr style="font-family: Graphik; font-size: 12px">
      <th scope="row" class="container">1</th>
        {% for question in latest_question_list %}
            <td><li style="font-weight: 500;"><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li></td>
        {% endfor %}
        <td><button type="button" class="btn btn-danger btn-sm badge-pill" style="font-size: 11px; width:60px" data-toggle="modal" data-target="#new">Edit</button></td>
    </tr>
    <tr style="font-family: Graphik; font-size: 12px"> 
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td><button type="button" class="btn btn-danger btn-sm badge-pill" style="font-size: 11px; width:60px" data-toggle="modal" data-target="#new">Edit</button></td>
    </tr>
    <tr style="font-family: Graphik; font-size: 12px">
      <th scope="row">3</th>
      <td colspan="2">Larry the Bird</td>
      <td><button type="button" class="btn btn-danger btn-sm badge-pill" style="font-size: 11px; width:60px"data-toggle="modal" data-target="#new">Edit</button></td>
    </tr>
  </tbody>
</table>

在此处输入图像描述

所需表 在此处输入图像描述

标签: htmldjangotwitter-bootstrapsqlite

解决方案


试试这个:

   <table class="table table-hover">
      <thead>
        <tr style="font-family: Graphik Black; font-size: 14px">
          <th scope="col">#</th>
          <th scope="col">First</th>
          <th scope="col">Last</th>
          <th scope="col">Action</th>
        </tr>
      </thead>
      <tbody>
        {% for question in latest_question_list %}
        <tr style="font-family: Graphik; font-size: 12px">
          <td><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li></td>
          <td>{{ question.answer }}</td>
          <td>{{ question.pub_date }}</td>
          <td><button type="button" class="btn btn-danger btn-sm badge-pill" style="font-size: 11px; width:60px" data-toggle="modal" data-target="#new">Edit</button></td>
        </tr>
        {% endfor %}
      </tbody>
    </table>

推荐阅读