django-通过用户id取相同表的昵称-分页功能

分页功能

#添加分页器
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

@login_required()
def index(request,page):
    wzalllist=Wzbiao.objects.all().order_by('-wzrq')
#下面数字为每页显示几条数据
    paged=Paginator(wzalllist,2)
    try:
        page=int(request.GET.get('page',1))
        wzalllist=paged.page(page)
    except:
        wzalllist = paged.page(1)

    content = {}
    content['wzalllist'] = wzalllist
#locals()表示传递所有变量
    return render(request, 'index.html', locals())
<div >
    <ul >
    {% if wzalllist.has_previous %}
    <li ><a href="?page={{ wzalllist.previous_page_number }}{% if request.GET.year %}&year={{ request.GET.year }}{% endif %}{% if request.GET.month %}&month={{ request.GET.month }}{% endif %}{% if request.GET.cid %}&cid={{ request.GET.cid }}{% endif %}">&laquo;上一页</a></li>
    {% else %}
    <li >&laquo;上一页</li>
    {% endif %}

     <li >{{ wzalllist.number }}/{{ wzalllist.paginator.num_pages }}</li>
    {% if wzalllist.has_next %}
      <li ><a href="?page={{ wzalllist.next_page_number }}{% if request.GET.year %}&year={{ request.GET.year }}{% endif %}{% if request.GET.month %}&month={{ request.GET.month }}{% endif %}{% if request.GET.cid %}&cid={{ request.GET.cid }}{% endif %}">下一页 &raquo;</a></li>
    {% else %}
      <li >下一页 &raquo;</li>
    {% endif %}
   </ul>
</div>

上面需要替换wzalllist为传递的列表

猜你喜欢

转载自blog.csdn.net/huanghong6956/article/details/84978146