title: Django Token and Session auth
body: <p>I was creating a Login For Custom User model is work fine with django , now i try to convert into Rest .</p>
  
  <p>It is creating the token but it doesnot return the token and Session is also blank </p>
  
  <p><em>(generation token but serializer.data is blank)</em>
  <a href="https://i.stack.imgur.com/9ODG2.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p><em>(Session db is empty)</em>
  <a href="https://i.stack.imgur.com/STWoI.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>django <strong>Serializer.py</strong></p>
  
  <pre><code>class UserLoginSerializer(serializers.ModelSerializer):
  email = serializers.EmailField(
      required=False,
      allow_blank=True,
      write_only=True,
      label="Email "
  )
  
  password = serializers.CharField(
      required=True,
      write_only=True,
      style={'input_type': 'password'}
  )
  
  class Meta(object):
      model = User
      fields = ['email', 'password']
  
  def validate(self, data):
      email = data.get('email', None)
      password = data.get('password', None)
  
      if not email:
          raise serializers.ValidationError("Please enter email to login.")
  
      user = User.objects.filter(Q(email=email)).exclude(email__iexact="").exclude(email__isnull=True).distinct()
      if user.exists():
          user1 = authenticate(email=email, password=password)
          if user1 is not None:
              if user1.is_active:
                  token, created = Token.objects.get_or_create(user=user1)
                  data['token'] = token
              else:
                  raise serializers.ValidationError("Account not active.")
          else:
              raise serializers.ValidationError("Invalid credentials.")
      else:
          raise serializers.ValidationError("This email is not valid.")
  
  
      return data
  </code></pre>
  
  <p>Django <strong>view.py</strong></p>
  
  <pre><code>class UserLogin(views.APIView):
  permission_classes = (permissions.AllowAny, )
  serializer_class = UserLoginSerializer
  
  def post(self, request):
      serializers = self.serializer_class(data=request.data)
      print(serializers)
      if serializers.is_valid(raise_exception=True):
          print("data", serializers.data)
          return Response(serializers.data, status=status.HTTP_200_OK)
      return Response(serializers.errors, status=status.HTTP_400_BAD_REQUEST)
  </code></pre>