【问题标题】:Paragraph element prepending not appending to table in django html段落元素前置不附加到 Django html 中的表格
【发布时间】:2017-08-08 21:28:53
【问题描述】:

我正在使用 Django Web 框架,并且我有一个 html 表,其中显示了我的一个表中的一些字段。如果没有要显示的字段(查询集中的记录),我从 python 传递 variable = "0"。

在这种情况下,我想将文本附加到表格中,以便它出现在在我的表格下方。但它出现在我的桌子上方......

<div class="1" style="overflow-x:auto;">
    <table id="1" class="1">
        <tr>
            <th>Heading 1</th>
            <th>Heading 2</th>
        </tr>
        {% ifequal variable "0" %}
            <p>No items to show</p>
        {% else %}
            <--append some fields-->
        {% endifnotequal %}
    </table>
</div>

如果我添加的字段可以正常工作,它们会按预期显示,但在其他情况下,它会添加到表格上方...

为什么?救命!

【问题讨论】:

    标签: python html django


    【解决方案1】:

    您似乎没有正确执行此操作。我认为有一个标签可以将文本放在表格下方,可以吗?

    使用末尾的标签(这是一个特定于表格的标签,比如和)。

    但是你需要使用这个 CSS:

    caption {
        caption-side: bottom;
    }
    

    你可以查看这个codepen:

    https://codepen.io/anon/pen/XMzPjb

    【讨论】:

      【解决方案2】:

      您不能在&lt;tr&gt; 中使用&lt;p&gt;,只允许使用&lt;td&gt;&lt;th&gt;

      你想把它改成:

      <div class="1" style="overflow-x:auto;">
          <table id="1" class="1">
              <tr>
                  <th>Heading 1</th>
                  <th>Heading 2</th>
              </tr>
          {% ifequal variable "0" %}
              </table>
              <p>No items to show</p>
          {% else %}
              <--append some fields-->
          {% endifnotequal %}
      </div>
      

      This question 可能对你也有帮助

      【讨论】:

      • 啊,它做到了。因为我可能会附加字段,所以我已经在标签内移动了 。谢谢!!
      • 嗯,那是有道理的,在我看到这条评论之前,我拒绝了你的编辑抱歉。如果您再次编辑它,我可以批准,我的错!
      猜你喜欢
      • 1970-01-01
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 2018-02-18
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多