title: Django: login_required on ajax call
body: <p>I am trying to authenticate user on ajax post but doesn't work. Here what I have done</p>
  
  <p><strong>settings.py</strong></p>
  
  <pre><code>LOGIN_URL = '/accounts/login/'
  LOGIN_REDIRECT_URL = '/'
  </code></pre>
  
  <p><strong>Template</strong></p>
  
  <pre><code>&lt;script&gt;
    $('.btn-request').click(function(){
          var button = this;
          $.ajax({
                   type: "POST",
                   url: "{% url 'like' %}",
                   data: {'tutorial_id': $(this).attr('name'), 'csrfmiddlewaretoken': '{{csrf_token}}'},
                   dataType: "json",
                   success: function(json) {
                      toastr.success(json.message);
  
                    },
                    error: function(rs, e) {
                          alert(rs.responseText);
                    }
              });
        })
    &lt;/script&gt;
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>url(r'^like/$', 'apps.quotation.views.like', name='like'),
  </code></pre>
  
  <p><strong>views.py</strong> - try 1</p>
  
  <pre><code>@login_required
  def like(request):
          vars = {}
          if request.method == 'POST':
              response_dict = {}
  
              if not something:
                  response_dict.update({'message': "Requested" })
              else:
                  response_dict.update({'message': "You have already requested" })
  
          return HttpResponse(simplejson.dumps(response_dict),
                          mimetype='application/javascript')
  </code></pre>
  
  <p><strong>views.py</strong> - try 2</p>
  
  <pre><code>def like(request):
      if not request.user.is_authenticated():
          return HttpResponseRedirect('/accounts/login')
      else:
          vars = {}
          if request.method == 'POST':
              response_dict = {}
              if not something:
                  response_dict.update({'message': "Requested" })
              else:
                  response_dict.update({'message': "You have already requested" })
  
          return HttpResponse(simplejson.dumps(response_dict),
                          mimetype='application/javascript')
  </code></pre>
  
  <p><strong>Runserver log</strong></p>
  
  <pre><code>[05/Mar/2014 05:19:16] "POST /like/ HTTP/1.1" 302 0
  [05/Mar/2014 05:19:16] "GET /accounts/login/?next=/like/ HTTP/1.1" 200 5610
  </code></pre>
  
  <p>What I am missing?</p>