from rest_framework_simplejwt.views import TokenObtainPairView class LoginView(TokenObtainPairView): serializer_class = CustomTokenObtainPairSerializer
from rest_framework_simplejwt.views import TokenObtainPairView from rest_framework.response import Response class UserLoginView(TokenObtainPairView): def post(self, request, *args, **kwargs): response = super().post(request, *args, **kwargs) response.data['username'] = request.data['username'] return responseIn this example, we create a custom view called UserLoginView that extends the TokenObtainPairView class. In the post() method of the view, we override the default behavior to add the username of the user to the JSON response returned by the TokenObtainPairView. Package: The TokenObtainPairView is a part of the Django REST framework SimpleJWT library, which is a third-party package that provides JSON Web Token authentication for Django REST framework.