@api_view(['GET'])
@authentication_classes([WebpageTokenAuth])
@permission_classes([IsAuthenticated, IsSuperuser])
def create_api_token(request):
    try:
        user = request.user
        with transaction.atomic():
            APIToken.objects.filter(user=user).delete()
            api_token = APIToken.objects.create(user=user)
        return Response({'auth_token': api_token.key}, status=status.HTTP_201_CREATED)
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
@api_view(['GET'])
@authentication_classes([WebpageTokenAuth])
@permission_classes([IsAuthenticated, IsSuperuser])
def create_api_token(request):
    try:
        user = request.user
        with transaction.atomic():
            APIToken.objects.filter(user=user).delete()
            api_token = APIToken.objects.create(user=user)
        return Response({'auth_token': api_token.key}, status=status.HTTP_201_CREATED)
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)