from .serializers import UserSerializer from rest_framework import status from rest_framework.response import Response from rest_framework.generics import CreateAPIView from rest_framework.authtoken.models import Token from django.contrib.auth.models import User class RegisterView(CreateAPIView): queryset = User.objects.all() serializer_class = UserSerializer # Create a UserSerializer to handle user registration. def perform_create(self, serializer): user = serializer.save() token, _ = Token.objects.get_or_create(user=user) return Response({'token': token.key}, status=status.HTTP_201_CREATED)