urls.py

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^show/', views.show_view, name='show')
]

Copy the code

Create the show_view function in views.py

from django.http import HttpResponse from django.shortcuts import render from .models import * from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage from django.http import JsonResponse def show_view(request): Num = request.get.GET ('num', 1) n = int(num) # 1 Stus = student.objects. all() # get all the data from # django Paginator(django stus, 2) # get all the data from this page try: stuss = Student.objects.all().values() students = list(stuss) return JsonResponse({'code': 200, 'data': Students}) perpage_data = pager.page(n) # except PageNotAnInteger: Perpage_data = pager.page(1) # return data except EmptyPage: perpage_data = pager.page(pager.num_pages) return render(request, 'show.html', {'show': stus, 'pager': pager, 'perpage_data': perpage_data})Copy the code