[Fixed]-Not able to authenticate using the django rest framework (request.user = AnonymousUser)

1👍

It looks like you have a regular Django view, so none of the rest framework authentication code will run.

def uuid_details(request, uuid):

You could use the api_view decorator to turn this into a rest framework view.

from rest_framework.response import Response
from rest_framework.decorators import api_view

@api_view(['GET'])
def uuid_details(request, uuid):
    return Response({"message": "user: " + str(request.user)}

0👍

Two things:

  1. @csrf_exempt doesn’t work on DRF views. It’s for raw Django ones.
  2. You didn’t use the DRF decorator for function views

It should work once those two points are fixed.

Leave a comment