title: CSRF verification failed. Request aborted, Reason for failure is CSRF cookie not set
body: <p>I want to realize a login for my site. I basically followed the online tutorial and followed the same exact way. However, I still get an error (CSRF verification failed. Request aborted.), when submitting my registration form. Can somebody tell me what raised this error and how to fix it?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>from django.shortcuts import render
  from rest_framework.status import (
      HTTP_400_BAD_REQUEST,
      HTTP_404_NOT_FOUND,
      HTTP_200_OK
  )
  from rest_framework import status,views
  from rest_framework.decorators import api_view
  from rest_framework.response import Response
  from django.contrib.auth import authenticate,login,logout
  from django.views.decorators.csrf import csrf_exempt
  from rest_framework.authtoken.models import Token
  from rest_framework.decorators import permission_classes
  from rest_framework.permissions import AllowAny
  
  
  @csrf_exempt
  @api_view(["POST"])
  @permission_classes((AllowAny,))
  def login(request):
      username = request.data.get("username")
      password = request.data.get("password")
      if username is None or password is None:
          return Response({'error': 'Please provide both username and 
  password'},
                      status=HTTP_400_BAD_REQUEST)
  user = authenticate(username=username, password=password)
  if not user:
      return Response({'error': 'Invalid Credentials'},
                      status=HTTP_404_NOT_FOUND)
  token, _ = Token.objects.get_or_create(user=user)
  return Response({'token': token.key},
                  status=HTTP_200_OK)
  </code></pre>
  
  <p>Getting output:</p>
  
  <pre><code>Forbidden (403)
  
  CSRF verification failed. Request aborted.
  
  You are seeing this message because this site requires a CSRF cookie when submitting forms. This cookie is required for security reasons, to ensure that your browser is not being hijacked by third parties.
  
   If you have configured your browser to disable cookies, please re-enable them, at least for this site, or for 'same-origin' requests.
  </code></pre>