Reputation: 2334
In views.py:
all_pages = 5
In html file:
{% if all_pages > 2 %}
<a href='...'>next</a>|<a href='...'>prev</a>
{% endif %}
{% if all_pages = page %}
<a href='...'>prev</a>
{% endif %}
But when I'm in 5th page, still both <a>
tags appear.
Why the second if
block does not work?
And how can I fix it?
============ for updating my question =========
in views.py:
def main(request):
list = PMenu.objects.all()
kol = request.META['PATH_INFO']
kol = kol[6:]
mylist = kol.split('-')
os = mylist[0]
sh = mylist[1]
en_chest_name = mylist[2]
cc = mylist[3]
page = mylist[4]
next_page = int(page) + 1
prev_page = int(page) - 1
senf = PDivContent.objects.get(id=cc)
#########################################################
users = PUser.objects.filter(ostan=os, shahr=sh, content_id=187)
#########################################################
all_users = 20
all_pages = math.ceil(all_users/4)
one = type(all_pages)
two = type(page)
#########################################################
And return part goes here...
In main.html:
current page: {{ page }}<br>
all users: {{ all_users }}<br>
all pages: {{ all_pages }}<br>
content_id: {{ cc }}<br>
next page: {{ next_page }}<br>
type of all_pages: {{ one }}<br> #output => 0
type of page: {{ two }} #output => was empty
<hr>
{% if all_pages == 1 %}
there is only one page
{% elif all_pages > 1 and page == '1' %}
<a href='/main/{{ os }}-{{ sh }}-{{ en_chest_name }}-{{ cc }}-{{ next_page }}'>next</a>
{% elif all_pages > 1 and page == all_pages %}
this is the last page
{% else %}
<a href='/main/{{ os }}-{{ sh }}-{{ en_chest_name }}-{{ cc }}-{{ next_page }}'>next</a>|<a href='/main/{{ os }}-{{ sh }}-{{ en_chest_name }}-{{ cc }}-{{ prev_page }}'>prev</a>
{% endif %}
Upvotes: 0
Views: 47
Reputation: 1340
page
seems to be a string type here not an integer while all_pages
is integer. So you can not compare them.
Also I would suggest to pass your variables as url arguments, instead of your current approach, it will be much cleaner and faster.
Upvotes: 1