Error de django: probé todo lo sugerido por todos los sitios web existentes en Google pero aún obtengo "El nombre de usuario dado debe estar configurado"

Estoy trabajando en el registro de usuarios para un sitio web de comercio electrónico. No estoy usando ningún formulario.py y no hay ningún problema de sangría. Estoy pasando JSON simple al cartero en el método POST para verificar si funciona o no, pero recibo errores. A continuación se muestra mi código y mi error. Estaré agradecido por su ayuda.

Mi modelo.py

from django.db import models
from django.contrib.auth.models import AbstractUser
import datetime

class User(AbstractUser):
    created_at=models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.user.username


Mi vista.py

class Register(APIView):
    def post(self, request):
        username = request.POST.get('username')
        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        password = request.POST.get('password')
        confirm_password = request.POST.get('confirm_password')
        email = request.POST.get('email')
        if password == confirm_password:
            if Client.objects.filter(username = username).exists():
                return Response({"message": "this username already exist"})
            elif Client.objects.filter(email = email).exists():
                return Response({"message": "This emaila address is already taken"})
            else:
                user= Client.objects.create_user(username = username, password =confirm_password, 
                                                 email=email)
                user.save()
        else:
            return Response({"message": "Try it again"}, 404)

Mis urls.py

from django.urls import path
from user_authentication.views import Login, Logout, Register

urlpatterns = [
    path('login/', Login.as_view()),
    path('logout/', Logout.as_view()),
    path('register/', Register.as_view()),
]

Error --- Valor de excepción: se debe establecer el nombre de usuario dado

Internal Server Error: /register/
Traceback (most recent call last):
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\garments\user_authentication\views.py", line 40, in post
    user= Client.objects.create_user(username = username, password =confirm_password, email=email)
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\django\contrib\auth\models.py", line 152, in create_user
    return self._create_user(username, email, password, **extra_fields)
  File "C:\Users\Lenovo\Documents\GitHub\E-commerce\venv\lib\site-packages\django\contrib\auth\models.py", line 137, in _create_user
    raise ValueError('The given username must be set')
ValueError: The given username must be set

El JSON que paso es: {"username":"bilalahmed", "first_name":"Bilal", "last_name":"Ahmed", "password":"bilal1234", "email":"[email protected] com"}

Answer