Quantcast
Viewing all articles
Browse latest Browse all 3667

Page not found Django restframework

I'm trying to write an API in Django to get the user comments from the URL.

My API is :

class ListSpecificUserCommentsApiView(APIView):    authentication_classes = [authentication.TokenAuthentication]    permission_classes = [permissions.AllowAny]    def get(self, request: HttpRequest, user) -> Response:        username: User = User.objects.get(id=user.id)        comments: Comment = Comment.objects.filter(user=username)        serialized_comments: CommentModelSerializer = CommentModelSerializer(instance=comments, many=True).data        return Response(serialized_comments)

and my urls.py :

urlpatterns = [    path(        route='users',        view=views.ListUsersApiView.as_view(),        name='users',    ),    path(        route='comments/<user>',        view=views.ListSpecificUserCommentsApiView.as_view(),        name='user-comments',    ),]

and still I'm facing this Page not found error.

I tried to pass the user as data in DRF Response like the code below:

class ListSpecificUserCommentsApiView(APIView):    authentication_classes = [authentication.TokenAuthentication]    permission_classes = [permissions.AllowAny]    def get(self, request: HttpRequest, user) -> Response:        username: User = User.objects.get(id=user.id)        comments: Comment = Comment.objects.filter(user=username)        serialized_comments: CommentModelSerializer = CommentModelSerializer(instance=comments, many=True).data        return Response(serialized_comments, data=user)

but it didn't work.


Viewing all articles
Browse latest Browse all 3667

Trending Articles