Hi i want to paginating queryset(lectures). and i tried. but it doesn'work how can i do?
class tag_detail(View): def get(self, request, pk): tag_hit = get_object_or_404(TagModel, id=pk) tag_hit.view_cnt = tag_hit.view_cnt + 1 tag_hit.save() tag = TagModel.objects.get(id=pk) lectures_data = LectureModel.objects.filter(tags__id=pk).order_by('-id') paginator = Paginator(lectures_data, 2) page = request.GET.get('page') try: lectures = paginator.page(page) except PageNotAnInteger: lectures = paginator.page(1) except EmptyPage: lectures = paginator.page(paginator.num_pages) return render(request, 'web/html/tag/tag_detail.html',{ 'lectures':lectures 'tag':tag })
Just make it a
ListView
and you won't have to worry about how it all works sincepaginate_by
sets up pagination for you