How to get the currently logged in user in django restframework?

I am trying to get the currently logged in user using django restframework and i have written a simple APIView to do this, but when i access the api_view it shows {"detail": "Authentication credentials were not provided."}, how do i provide the authentication credentials?

How do i provide the authentication details, login and see the user information maybe (username and email)

class MyProfileView(APIView):
    permission_classes = [permissions.IsAuthenticated]

    def get(self, request):
        user = User.objects.get(request.user)
        return Response(user.data)

Are you including the token with this request? (Token-based authentication requires the token be sent with every request requiring authentication. It does not cause a session to be established.)

You might want to review the docs at Authentication - Django REST framework.

1 Like

I am using postman and i can’t figure out how to inlcude the token with the request?
can you please help me out here?

The header value you need to set is described in the docs for Token Authentication.

1 Like

That did it for me, thanks alot.