0

So I have an @api_view which is based on a post request, which has some parameters sent from the front end. I want to get the username of the loggedin user to perfrom some other actions. But request.user.username always returns "Anonymous User".

If I call request.user.username outside of this request function I get the logged in user returned correctly. What is going wrong here?

@api_view(['GET','POST']) 
def function(request):
    if request.method == 'POST':
        data = request.data 
        # perform some function
        username = request.user.username
        # perform some other actions
Jaron
  • 3
  • 3

0 Answers0