                  raise serializers.ValidationError('Unable to login with provided credentials.')
          else:
              raise serializers.ValidationError('Must include "username" and "password"')
  
      def convert_object(self, obj):
          ret = self._dict_class()
          ret['token'] = obj.key
          ret['user'] = obj.user.id
          return ret
  
      def restore_object(self, attrs, instance=None):
          token, created = Token.objects.get_or_create(user=attrs['user'])
          return token
 
</s> remove         if request.user.is_authenticated() and request.auth:
            request.auth.delete()
            return HttpResponse("logged out")
        else:
            return HttpResponse("not logged in")
    
 </s> add         serializer = AuthTokenSerializer(data=request.DATA)
        if serializer.is_valid():
            token, created = Token.objects.get_or_create(user=serializer.object['user'])
            return Response({'token': token.key})
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
 </s> remove 
class AuthTokenLogoutView(APIView):
 </s> add  </s> remove                                     {'username': self.username, 'password': self.password})
        self.assertEqual(response.status_code, 201)
        self.assertEqual(json.loads(response.content)['token'], self.key)

    def test_token_logout(self):
        """Ensure token logout view using JSON POST works."""
        # Use different User and Token as to isolate this test's effects on other unittests in class
        username = "ringo"
        user = User.objects.create_user(username, "starr@thebeatles.com", "pass")
        token = Token.objects.create(user=user)
        auth = "Token " + token.key
        client = Client(enforce_csrf_checks=True)
        response = client.post('/auth-token/logout/', HTTP_AUTHORIZATION=auth)
 </s> add                                {'username': self.username, 'password': self.password}) </s> remove                                     json.dumps({'username': self.username}), 'application/json')
 </s> add                                json.dumps({'username': self.username}), 'application/json') </s> remove     serializer_class = AuthTokenSerializer
 </s> add 
                  raise serializers.ValidationError('Unable to login with provided credentials.')
          else:
              raise serializers.ValidationError('Must include "username" and "password"')
  









keep keep keep keep replace replace replace replace replace replace replace replace replace
 Updates to login view for TokenAuthentication from feedback from Tom 
rest_framework/authtoken/serializers.py