Answer the question
In order to leave comments, you need to log in
How do I change a variable inside tempalte?
I have two variables and want to add and subtract inside tempalte.
I can't do it inside views.py since it's pagination.
!--Pagination-->
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
{% if movies.has_previous %}
<li class="page-item">
<a class="page-link" href="?page={{ movies.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1" aria-disabled="true">Previous</a>
</li>
{% endif %}
{% if movies.number|add:'-4' > 1 %}
<li class="page-item"><a class="page-link" href="?page={{ movies.number|add:'-5' }}">…</a></li>
{% endif %}
{% for i in movies.paginator.page_range %}
{% if movies.number == i %}
<li class="page-item active" aria-current="page">
<span class="page-link">
{{ i }}
<span class="sr-only">(current)</span>
</span>
</li>
{% elif i > movies.number|add:'-5' and i < movies.number|add:'5' %}
<li class="page-item"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if movies.paginator.num_pages > movies.number|add:'4' %}
<li class="page-item"><a class="page-link" href="?page={{ movies.number|add:'5' }}">…</a></li>
{% endif %}
{% if movies.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ movies.next_page_number }}">Next</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1" aria-disabled="true">Next</a>
</li>
{% endif %}
</ul>
</nav>
{{ i|add:'5'}}
{{ i|add:'-5'}}
{{ i|add:'4'}}
{{ i|add:'-4'}}
X == 5
{{ i|add:'{{x}}'}}
{{ i|add:'-{{x}}'}}
{{ i|add:'{{x}}-1'}}
{{ i|add:'-{{x}}-1'}}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question