@register.simple_tag def pre_ele(query_sets, filter_condtions,previous_orderby, search_text): c_tag =‘‘ filters = ‘‘ for k, v in filter_condtions.items(): filters += "&%s=%s" % (k, v) if query_sets.has_previous(): page_n = query_sets.previous_page_number() # page_n是指针指向点击位置的前一个,因此判断时我们认为是大于1,其实还要往前推一个,即减去1,所以此处>0 if page_n > 0: c_tag += ‘‘‘<li><a href="?page=1%s&o=%s&_q=%s">首页</a>‘‘‘ % (filters, previous_orderby, search_text) c_tag += ‘‘‘<li><a href="?page=%s%s&o=%s&_q=%s">上一页</a>‘‘‘ % (page_n, filters, previous_orderby, search_text) e_tag = ‘</li>‘ c_tag += e_tag return mark_safe(c_tag) @register.simple_tag def next_ele(query_sets, filter_condtions,previous_orderby, search_text): c_tag =‘‘ filters = ‘‘ for k, v in filter_condtions.items(): filters += "&%s=%s" % (k, v) if query_sets.has_next(): page_n = query_sets.next_page_number() # page_n是指针指向点击位置的后一个 pg_n = query_sets.paginator.num_pages #因为是判断后一页,要用到总页数减去pg_n指向的位置 #在这里的-1,代表指针跳出总页数的最后一个位置,总页数和它相减总是-1,这样才是最后的一页 if pg_n - page_n > -1: c_tag += ‘‘‘<li><a href="?page=%s%s&o=%s&_q=%s">下一页</a>‘‘‘ % (page_n, filters, previous_orderby, search_text) c_tag += ‘‘‘<li><a href="?page=%s%s&o=%s&_q=%s">尾页</a>‘‘‘ % (pg_n, filters, previous_orderby, search_text) e_tag = ‘</li>‘ c_tag += e_tag return mark_safe(c_tag)
原文地址:https://www.cnblogs.com/xuroke/p/10643494.html
时间: 2024-10-27 23:45:15