title: How do I apply login_required() in django?
body: <pre><code>from django.contrib.auth.decorators import login_required
  from views import PostListView
  urlpatterns = patterns('',
      (r'^test/$', PostListView.as_view(), name='test'),
  )
  </code></pre>
  
  <p>When I do this its as if Django completely ignores the login_required and goes straight to the template. I have authentication correctly setup. I can register new accounts into the MySQL database and login/authenticate successfully. Right now I just want to restrict some pages to registered users only. and have it basically stay logged in when you login. Like an actual site.</p>
  
  <p>Edit:</p>
  
  <p><code>views.py</code></p>
  
  <pre><code>from django.shortcuts import redirect, get_object_or_404, render, render_to_response
  from django.views.generic import ListView, DetailView
  from django.views.generic.edit import CreateView, UpdateView, DeleteView
  from django.views.generic.base import View, TemplateView
  from django.core.context_processors import csrf
  from models import *
  from forms import *
  from django.http import HttpResponseRedirect
  from django.contrib.auth.decorators import login_required
  from django.utils.decorators import method_decorator
  
  class PostListView(ListView):
      model = Post
      context_object_name = "post_list"
  
      @method_decorator(login_required)
      def get(self, request, *args, **kwargs):
          return super(PostListView, self).get(request, *args, **kwargs)
  
      def get_template_names(self):
          return ["app/list.html"]
  
      def get_queryset(self):
          posts = Post.objects
          if 'all_posts' not in self.request.GET:
              posts = posts.filter(is_published=True)                                                         
          return posts 
  </code></pre>