title: how to generate rest_framework_jwt token in the login process
body: <p>I'm trying to implement django-rest-framework-jwt for authentication. I did all what jwt tutorials said (adding the setting, url and curl testing). and I did successfully obtain the token using <code>127.0.0.1:8000/api/auth/token/</code> in the browsable api.</p>
  
  <p>but what I don't get is how to generate the token in the login process. My guess is to generate it in the LoginSerializer maybe? (or I misunderstood the concept!)</p>
  
  <p>Here's what I have:</p>
  
  <pre><code># settings.py
  REST_FRAMEWORK = {
      'DEFAULT_RENDERER_CLASSES': (
          'rest_framework.renderers.JSONRenderer',
          'rest_framework.renderers.BrowsableAPIRenderer',
      ),
      'DEFAULT_AUTHENTICATION_CLASSES': (
          'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
          'rest_framework.authentication.SessionAuthentication',
      ),
      'DEFAULT_PERMISSION_CLASSES': (
          'rest_framework.permissions.IsAuthenticated',
      ),
  }
  
  # project/urls.py
  url(r'^api/auth/token/', obtain_jwt_token),
  </code></pre>
  
  <p>login serializer and view:</p>
  
  <pre><code>class UserLoginSerializer(ModelSerializer):
      token = CharField(allow_blank=True, read_only=True)
      class Meta:
          model = User
          fields = ('username', 'password', 'token')
  
      def validate(self, data):
          username = data.get('username',None)
          password = data['password']
  
          user = authenticate(username=username, password=password)
          if not user or not user.is_active:
              raise ValidationError("Invalid username/password.")
  
          # generate jwt token ??
          # data['token'] = generated jwt token??
  
          return data
  
  
  class UserLoginAPIView(APIView):
      permission_classes = [AllowAny]
      serializer_class = UserLoginSerializer
  
      def post(self, request, *args, **kwargs):
          data = request.data
          serializer = UserLoginSerializer(data=data)
          if serializer.is_valid(raise_exception=True):
              new_data = serializer.data
              return Response(new_data, status=HTTP_200_OK)
          return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
  </code></pre>
  
  <p>So what do I have to do?</p>