if not username:
    return None
try:
    user = User.objects.get(username=username)
except User.DoesNotExist:
    raise exceptions.AuthenticationFailed('No such user')
return user, None
Django Rest Framework custom authentication