[Django]-Get rows count from django_tables2

6👍

You can check if there are any rows using the table’s rows attribute

{% if participations_table.rows %}
    {% render_table  participations_table %}
{% endif %}

In the django template, you can get the number of rows with the length filter.

{{ participations_table.rows|length }}

Or in the view, simply

len(participations_table.rows)

Alternatively, you could decide to always display the table, and customize the empty_text attribute which is displayed when the table is empty.

Leave a comment