[Answer]-Error in the template with Django : can I make arithmetic in if statement

1👍

✅

The modulus (%) operator is not available in django templates. However, you can use the divisibleby (https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#divisibleby) template filter, something like

{% if forloop.counter|divisibleby:"2" %}

0👍

Use the paginator, your QuerySet are not evaluated for the hole table, just the number you need to build the page, and it offers properties that you can use in the template like (page_range, next_page_number, has_next, etc.)
here is the code withe BootStrap 2 and django.core.paginator:

   <div class="pagination pagination-centered">
        <ul>
            {% if MYDATAENTIRES.has_previous %}
                <li>
                    <a href="?page={{ MYDATAENTIRES.previous_page_number }}">{% trans "Précédent" %}</a>
                </li>
            {% endif %}
            {% for i in MYDATAENTIRES.paginator.page_range %}
              <li {% ifequal MYDATAENTIRES.number i %} {{ 'class="disabled"' }} {% endifequal %}>
                  <a href="?page={{ i }}">
                    {{ i }}
                  </a>
              </li>     
            {% endfor %}
            {% if MYDATAENTIRES.has_next %}
                <li>
                    <a href="?page={{ MYDATAENTIRES.next_page_number }}">{% trans "Suivant" %}</a>
                </li>
            {% endif %}
        </ul>
    </div>

Leave a comment