title: Django @login_required for class views
body: <p>I inherited a Django(1.5.1) project and I need to put one view behind a <code>@login_required</code> decorator.  Here is what i have in <code>views.py</code>:</p>
  
  <p>I got this snippet of code from <a href="http://brack3t.com/our-custom-mixins.html" rel="noreferrer">here</a> and it looks like its purpose is to allow someone to apply the <code>@login_required</code>decorator to a <code>class</code></p>
  
  <pre><code>class LoginRequiredMixin(object):
      """
      View mixin which verifies that the user has authenticated.
  
      NOTE:
          This should be the left-most mixin of a view.
      """
  
      @method_decorator(login_required)
      def dispatch(self, *args, **kwargs):
          return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)
  
  
  class PermissionRequiredMixin(object):
      login_url = settings.LOGIN_URL
      permission_required = None
      raise_exception = False
      redirect_field_name = '/workers/'
  
      def dispatch(self, request, *args, **kwargs):
          # Verify class settings
          if self.permission_required == None or len(
              self.permission_required.split(".")) != 2:
              raise Error("'PermissionRequiredMixin' requires "
                  "'permission_required' attribute to be set.")
  
          has_permission = request.user.has_perm(self.permission_required)
  
          if not has_permission:
              if self.raise_exception:
                  return HttpResponseForbidden()
              else:
                  path = urlquote(request.get_full_path())
                  tup = self.login_url, self.redirect_field_name, path
                  return HttpResponseRedirect("%s?%s=%s" % tup)
  
          return super(PermissionRequiredMixin, self).dispatch(
              request, *args, **kwargs)
  </code></pre>
  
  <p>I then apply this to the view i want to add permissions to like so: </p>
  
  <pre><code>class RootWorkerView(LoginRequiredMixin, PermissionRequiredMixin, APIView):
      renderer_classes = (WorkersJSONRenderer, JSONRenderer,
                          BrowsableAPIRenderer)
  
      def get(self, request):
          worker_list = rest_models.WorkerList(request)
          serializer = WorkerListSerializer(worker_list)
          return Response(serializer.data)
  </code></pre>
  
  <p>The <code>APIView</code> argument is a carry over, as before it was the only argument.  Is this correct? </p>
  
  <p>When run, I get nothing.  The template for the view I want to secure shows up with no login prompt. </p>
  
  <p>Relevant snippet from <code>urls.py</code>:</p>
  
  <pre><code>url(r'^workers/$', views.RootWorkerView.as_view(),
      name='root_worker_view'),
  
  url(r'^login/$', 'django.contrib.auth.views.login',
      {'template_name': 'dashboard/login.html'}),
  </code></pre>
  
  <p><code>/login/</code> does work, and I can login successful, so that's not the issue. </p>
  
  <p>I feel like <code>@method_decorator(login_required)</code> isnt doing its job.  Any ideas?</p>