title: Django 2.1 Token matching query does not exist
body: <p>I've been trying to implement user authenitication in Django using <code>rest_framework.authtoken</code> as in <a href="https://iheanyi.com/journal/user-registration-authentication-with-django-django-rest-framework-react-and-redux/" rel="nofollow noreferrer">this guide</a>. My test cases, which test for a range of different errors that could arise while a user logs in, are working properly before access tokens are introduced into the code. </p>
  
  <p>For some reason, when I add in a check for the token returned in an Http response, I get the error:</p>
  
  <p><code>rest_framework.authtoken.models.Token.DoesNotExist: Token matching query does not exist.</code></p>
  
  <p>I've added in all of the relevant imports that should be needed to check for tokens so <strong>could there be a function that was relocated to a different library in one of the more recent django versions? What might be causing the issue?</strong></p>
  
  <p><strong>test.py</strong></p>
  
  <pre><code>from django.urls import reverse 
  from rest_framework.test import APITestCase
  from django.contrib.auth.models import User
  from rest_framework import status
  from rest_framework.authtoken.models import Token
  
  
  class AccountsTest(APITestCase):
      def setUp(self):
          # We want to go ahead and originally create a user. 
          self.test_user = User.objects.create_user('testuser', 'test@example.com', 'testpassword')
          print('test user:' + str(self.test_user))
  
          # URL for creating an account.
          self.create_url = reverse('account-create')
  
      def test_create_user(self):
          """
          Ensure we can create a new user and a valid token is created with it.
          """
          data = {
                  'username': 'foobar',
                  'email': 'foobar@example.com',
                  'password': 'somepassword'
                  }
  
          response = self.client.post(self.create_url , data, format='json')
          user = User.objects.latest('id')
  
          token = Token.objects.get(user=user)
          self.assertEqual(response.data['token'], token.key)
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from rest_framework.views import APIView
  from rest_framework.response import Response
  from rest_framework import status
  from accounts.serializers import UserSerializer
  from django.contrib.auth.models import User
  from rest_framework.authtoken.models import Token
  
  class UserCreate(APIView):
      """ 
      Creates the user. 
      """
  
      def post(self, request, format='json'):
          serializer = UserSerializer(data=request.data)
          if serializer.is_valid():
              user = serializer.save()
              if user:
                  token = Token.objects.create(user=user)
                  json = serializer.data
                  json['token'] = token.key
                  return Response(json, status=status.HTTP_201_CREATED)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  </code></pre>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      #third party
      'rest_framework',
      'rest_framework.authtoken',
  
  REST_FRAMEWORK = {
      'DEFAULT_AUTHENTICATION_CLASSES': (
      'rest_framework.authentication.TokenAuthentication',
      ),
      'DEFAULT_PERMISSION_CLASSES': (
      'rest_framework.permissions.IsAuthenticatedOrReadOnly',
      ),
  }
  </code></pre>