0

I'm using the Django Web Framework and I have a html table displaying some fields from one of my tables. If there are no fields to display (records in a queryset), I pass variable = "0" from python.

I want to append text to the table in this case so it appears underneath my table. But it's appearing above my table....

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

If I'm appending the fields this works fine they appear as expected, but in the other case it prepends above the table instead...

Why? Help!

Ruth Young
  • 870
  • 2
  • 14
  • 37

2 Answers2

1

You can't use <p> inside a <tr> only <td> and <th> are allowed.

You'd want to change it to:

<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 might be helpful for you too

Community
  • 1
  • 1
Dan Gamble
  • 3,965
  • 1
  • 24
  • 44
  • Ah this did it. Because I append fields potentially I have moved the inside the tag. Thank you!! – Ruth Young Mar 17 '17 at 10:57
  • Ah that makes sense then, i rejected your edit sorry before i saw this comment. If you edit it again i can approve, my bad! – Dan Gamble Mar 17 '17 at 10:59
0

It seems that you're not doing this correctly. I think there is a tag for putting text below tables, could it be ?

Use the tag at the end (this is a table specific tag, like and ).

But you will need to use this CSS:

caption {
    caption-side: bottom;
}

You can check this codepen:

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

madtyn
  • 1,469
  • 27
  • 55