api_view GET permission_classes IsAuthenticated def api_list_post_view

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
@api_view(['GET', ])
@permission_classes((IsAuthenticated,))
def api_list_post_view(request):
post_list = Post.objects.all()
paginator = Paginator(post_list, 1)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
if request.method == "GET":
serializer = PostSerializer(page_obj, many=True)
return Response(serializer.data)