在views.py中:
all_pages = 5
在html文件中:
{% if all_pages > 2 %}
<a href='...'>next</a>|<a href='...'>prev</a>
{% endif %}
{% if all_pages = page %}
<a href='...'>prev</a>
{% endif %}
但是当我进入第5页时,仍然会同时<a>
显示两个标签。
为什么第二个if
块不起作用?
我该如何解决?
============用于更新我的问题=========
在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...
在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 %}
page
似乎是一个字符串类型,这里不是整数,all_pages
而是整数。所以你不能比较它们。另外,我建议将变量作为url参数传递,而不是您当前的方法,它将更加整洁和快捷。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句