title: How to return user details in response after login in django rest_framework
body: <p>Hi I am beginner in Django Here I want user email and name in response after user login using api. Thanks in advance for your help.</p>
  
  <p>models.py 
  I want user email and user name in response only getting auth token in response</p>
  
  <pre><code>class UserManager(BaseUserManager):
  
      def create_user(self, email, password, **extra_fields):
          if not email:
              raise ValueError('Users must have an email address')
  
          if not password:
              raise ValueError('Users must have a password')
  
          user = self.model(email=self.normalize_email(email), **extra_fields)
          user.set_password(password)
          user.save(using=self._db)
  
          return user
  
      def create_superuser(self, email, password):
          user = self.create_user(email,password)
          user.is_staff = True
          user.is_superuser = True
          user.save(using=self._db)
  
          return user
  
  class User(AbstractBaseUser, PermissionsMixin):
      email = models.EmailField(max_length=255, unique=True)
      name = models.CharField(max_length=255)
      is_active = models.BooleanField(default=True)
      is_staff = models.BooleanField(default=False)
  
      objects = UserManager()
  
      USERNAME_FIELD = 'email'
  </code></pre>
  
  <p>serializers.py
  I want user email and user name in response only getting auth token in response</p>
  
  <pre><code>class UserSerializer(serializers.ModelSerializer):
      email = serializers.EmailField(
              required=True,
              validators=[UniqueValidator(queryset=User.objects.all())]
              )
      class Meta:
          model = get_user_model()
          fields = ('email', 'password', 'name')
          extra_kwargs = {'password': {'write_only': True, 'min_length': 6}}
  
          def create(self, validated_data):
              user = User.objects.create_user('name',validated_data['email'],
                  validated_data['password'],)
              return user
  
  class AuthTokenSerializer(serializers.Serializer):
  
      email = serializers.CharField()
      password = serializers.CharField(
          style = {'input_type':'password'},
          trim_whitespace = False
      )
  
      def validate(self, attrs):
  
          email = attrs.get('email')
          password = attrs.get('password')
  
          user = authenticate(
              request = self.context.get('request'),
              username = email,
              password = password
          )
  
          if not user:
  
              msg = _('Unable to authenticate with provided crenditial')
              raise serializers.ValidationError(msg, code = 'authorization')
  
          attrs['user'] = user
  
          return attrs
  </code></pre>
  
  <p>urls.py
  I want user email and user name in response only getting auth token in response</p>
  
  <pre><code>path('api/login/',views.CreateTokenView.as_view(),name='token'),
  </code></pre>
  
  <p>View file for creating view and I dont now how to return user from Auth token. I want user email and user name in response only getting auth token in response
  views.py</p>
  
  <pre><code>class UserCreate(APIView):
      """
      Creates the user.
      """
  
      def post(self, request, format='json'):
          serializer = UserSerializer(data=request.data)
          if serializer.is_valid():
              user = serializer.save()
              if user:
                  token = Token.objects.create(user=user)
                  json = serializer.data
                  json['token'] = token.key
                  return Response(json, status=status.HTTP_201_CREATED)
  
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  
  
  class CreateTokenView(ObtainAuthToken):
  
      serializer_class = AuthTokenSerializer
      renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES
  
  
  
      def post(self, request, *args, **kwargs):
          response = super(CreateTokenView, self).post(request, *args, **kwargs)
          token = Token.objects.get(key=response.data['token'])
          return Response({'token': token.key})
  </code></pre>