Пример #1
0
def books(request):
    print(request.GET)
    # < QueryDict: {'page': ['11']} >
    # 获取page.py中的s = f'<li><a href="?page={i}">{i}</a></li>'
    # 即url上的?后面的参数
    current_page = request.GET.get('page')
    print(current_page)  #11 获取当前页码

    try:
        current_page = int(current_page)
    except:
        # 没有page参数或者不是数字字符串
        current_page = 1

    all_book_objs = Book.objects.all()
    total_count = all_book_objs.count()  # 总数据量
    page_obj = Pagenation(current_page, total_count)  #新建对象

    book_objs = Book.objects.all()[page_obj.page_data_start:page_obj.
                                   end_data_start]

    # book_objs = models.Book.objects.all()[10:20] # 2
    # book_objs = models.Book.objects.all()[20:30] # 3
    return render(request, 'books.html', {
        'book_objs': book_objs,
        'page_obj': page_obj
    })
Пример #2
0
def books(request):
    pass
    # print(request.GET)
    current_page = request.GET.get('page')
    try:
        current_page = int(current_page)
        ##没有page参数或者不是数字字符串
    except:
        current_page = 1
    # print(current_page)  #1

    all_book_objs = Book.objects.all()
    # print(all_book_objs)
    total_count = all_book_objs.count()  # # 总数据量
    # print(total_count)  #28

    page_obj = Pagenation(current_page, total_count)
    # print(page_obj)

    book_objs = Book.objects.all()
    book_objs = book_objs[page_obj.page_data_start:page_obj.end_data_start]

    # book_objs = models.Book.objects.all()[10:20] # 2
    # book_objs = models.Book.objects.all()[20:30] # 3

    # return HttpResponse('ok')
    return render(request, 'books.html', {
        'book_objs': book_objs,
        'page_obj': page_obj
    })
Пример #3
0
def books(request):
	current_page = request.GET.get('page')
	try:
		current_page = int(current_page)  #没有page参数或者不是数字字符串
	except:
		current_page = 1

	all_book_objs = models.Book.objects.all()
	total_count = all_book_objs.count()  # 总数据量
	page_obj = Pagenation(current_page, total_count)


	book_objs = models.Book.objects.all()[page_obj.page_data_start:page_obj.end_data_start]

	# book_objs = models.Book.objects.all()[10:20] # 2
	# book_objs = models.Book.objects.all()[20:30] # 3

	return render(request, 'books.html',
	              {'book_objs': book_objs, 'page_obj': page_obj})