python中如何去做一个简单的分页

python中如何去做一个简单的分页呢?

那么我就为大家演示一下

首先,我们导入分页模块
from django.core.paginator import Paginator

然后,我们在模板中导入js文件和css样式

最后我们做一个简单的示范

    page_count = 3
    current_page = int(request.GET.get('p', 1))
    goods = Computer.objects.all()
    pag = Paginator(goods, page_count)
    goods_list = pag.get_page(current_page)
    total_page = pag.num_pages
    return render(request,'index.html',{'goods_list':goods_list,'current_page':current_page,'total_page':total_page})

$("#pagination").pagination({
currentPage: {{current_page}},totalPage: {{total_page}}, callback: function(current) {
window.location.href="/index/?p="+current }});

你可能感兴趣的:(框架配置基础)