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
- I disabled the csrf token
- added CSRF_TRUSTED_ORIGINS
- created custom