1 ajax
$.ajax({
url:'/test/',
method:'get/post',
contentType:'application/json',
//processData:false
//contentType:false
data:json格式字符串,字典对象,formdata对象,
success:function (data){
//data的类型取决于,后端返回时指定的响应类型
1 分页器基本使用
详见终极使用
2 分页器终极用法
2.1 后端
def books_page(request):
current_num = int(request.GET.get('page_num', 1))
book_list = models.Books.objects.all()
paginator = Paginator(book_list, 20)
try:
page = paginator.page(current_num)
except Exception as e:
current_num = 1
page = paginator.page(current_num)
if paginator.num_pages > 11:
if current_num - 5 < 1:
page_range = range(1, 12)
elif current_num + 5 > paginator.num_pages:
page_range = range(paginator.num_pages - 10, paginator.num_pages + 1)
else:
page_range = range(current_num - 5, current_num + 6)
else:
page_range = paginator.page_range
return render(request, 'book_page.html', locals())
2.2 前端