title: django - login view in DRF
body: <p>I have a register view in my django code which works fine:</p>
  
  <p>Working in Django rest framework,</p>
  
  <pre><code>class UserViewSet(viewsets.ReadOnlyModelViewSet):
      queryset = User.objects.all()
      serializer_class = UserSerializer
  
      @list_route(methods=['post'])
      def register(self, request):
          serializer = UserSerializer(data=request.DATA)
          if serializer.is_valid():
              serializer.save()
              return Response(serializer.data, status=status.HTTP_201_CREATED)
          else:
              return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  </code></pre>
  
  <p>Now I want to add a login view in order to let users login, I wrote something like this, not sure about this:</p>
  
  <pre><code>@list_route(methods=['post'])
      def login(self, request):
          username = request.POST['username']
          password = request.POST['password']
  
          user = authenticate(username=username, password=password)
          if user is not None:
              if user.is_active:
                  login(request, user)
                  return Response(status=status.HTTP_200_OK)
              else:
                  return Response(status=status.HTTP_404_NOT_FOUND)
          else:
              return Response(status=status.HTTP_401_UNAUTHORIZED)
  </code></pre>
  
  <p>couple of questions:</p>
  
  <ul>
  <li>does it look okay?</li>
  <li>and also, how should I POST to this view? to the register view I POST with json and it works fine. 
  Will json with the username and password work here as well?</li>
  </ul>