[Answered ]-Create URL for detailview using DRF Modelviewset

1👍

You can make use of @action decorator.

Give this a try:

class UserAPI(viewsets.ModelViewSet):
   ...

    @action(detail=False)
    def profile(self, request):
        serializer = UserSerializer(request.user)
        return Response(serializer.data)

Now go to 127.0.0.1:8000/users/profile/, you should see the current authenticated user’s data.

0👍

this may be helpful.
You can use user = request.user.id , by in this way you can get current login user.

Leave a comment