14.1. Pagination

14.1.1. LimitOffsetPagination

  • /api/users?limit=10&offset=0

  • settings.NINJA_PAGINATION_PER_PAGE = 100

from ninja.pagination import paginate

@api.get('/users', response=List[UserSchema])
@paginate
def list_users(request):
    return User.objects.all()
curl http://127.0.0.1:8000/api/users?limit=10&offset=0

14.1.2. PageNumberPagination

from ninja.pagination import paginate, PageNumberPagination

@api.get('/users', response=list[UserSchema])
@paginate(PageNumberPagination, page_size=10)
def list_users(request):
    return User.objects.all()
curl http://127.0.0.1:8000/api/users?page=2