'Get request with django returns None for the user

I'm trying to get the details of the user who makes a get request in django. I'm using postman to perform the get request but when I try to print request.user and type(request.user):

#In the view
class SomeView(APIView):
    ....
    ....
    def get(self, request, pk, format=None):
        print(f'request: {request.user}, {type(request.user)')

I get None and None for the user and the type.

I've looked though many stackoverflow posts but I'm struggling finding out the reason.

From:

  1. Django username is empty in a GET request
  2. https://www.django-rest-framework.org/api-guide/authentication/

I thought perhaps I'm not performing the get request with a user, but if that is the case, I should be getting an Anonymous object as the type for user right? But instead it's telling me it's None

I should mention from postman I'm under the Authorization tab, I've tried using a Bearer Token which I know I had the correct token as well as (separately) using basic auth by having the username and the password. Either method results in request.user being None.

If I just print out request I get:

<rest_framework.request.Request: GET '/test/number/33574677/'>,

I'm not sure what the issue here is, does it have something to do with the way I'm using postman to send the request? Or perhaps I'm missing something very trivial? Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source