CSRF Failed: CSRF token missing

I am writing my code in django python, Here is my view.py

@csrf_exempt
@api_view(['POST'])
def Userlogin1(request):
    print('login working')
    username = request.data.get('username')
    password = request.data.get('password')
    user = authenticate(request=request._request, username = username, password = password)
    if user is not None:
        login(request._request, user)
        return Response({'message': 'login successful.'}, status=status.HTTP_200_OK)
    return Response({'error': 'Invalid credentials.', 'user':user, 'username':username, 'password':password}, status=status.HTTP_401_UNAUTHORIZED)

when i run this on the postman, on first POST request, postman returning a correct response <'message': 'login successful.> but on second and further hit, post man throwing 403 error with this message { "detail": "CSRF Failed: CSRF token missing." } after removing the cookies from postman, it can run once but shows again same issue

  1. I disabled the csrf token
  2. added CSRF_TRUSTED_ORIGINS
  3. created custom
Вернуться на верх