title: Ajax POST call Django's View with Multiple Data [Response 500]
body: <p>This 500 status error is NOT CSRFtoken problem after integrating django-secretballot with my app called 'flavor'. FireBug Network tab shows</p>
  
  <p>POST:</p>
  
  <pre><code>content_type    flavor.Flavor
  object_id   5
  vote    1
  Source
  content_type=flavor.Flavor&amp;object_id=5&amp;vote=1
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>TypeError at /flavor/vote/
  vote() missing 3 required positional arguments: 'content_type', 'object_id', and 'vote'
  </code></pre>
  
  <p><strong>Could you spot any mistake in my flavor_vote.js below?? Why can't those 3 required positional arguments be passed into the vote() function??</strong></p>
  
  <pre><code>$(document).ready(function() {
  
    var csrftoken = getCookie('csrftoken');
  
    $.ajaxSetup({
        beforeSend: function(xhr, settings) {
            if (!csrfSafeMethod(settings.type) &amp;&amp; !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrftoken);
            }
        },
        error: function(xhr, textStatus, error) {
            console.log(error);
        }
    });
  
    $(".vote").click(function () {
      var div = $(this);
      var obj_id = $(this).closest('.flavor').attr('flavor-id');
      var vote = 1;
      if ($(this).hasClass('voted')) {
          var vote = 0;
      }
  
     console.log(div);
      $.ajax({
          url: '/flavor/vote/',
          method: 'post',
          data: {
              'content_type': 'flavor.flavor',
              'object_id': obj_id,
              'vote': vote
          },
          success: function (data) {
              alert('Successfully called');
              $(div).toggleClass('btn-success voted');
              console.log(data);
          },
          error: function(data) {
              console.log(data);
          }
      });
    });
  });
  
  function getCookie(name) {
      var cookieValue = null;
      if (document.cookie &amp;&amp; document.cookie != '') {
          var cookies = document.cookie.split(';');
          for (var i = 0; i &lt; cookies.length; i++) {
              var cookie = jQuery.trim(cookies[i]);
              // Does this cookie string begin with the name we want?
              if (cookie.substring(0, name.length + 1) == (name + '=')) {
                  cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                  break;
              }
          }
      }
      return cookieValue;
  }
  
  function csrfSafeMethod(method) {
      // these HTTP methods do not require CSRF protection
      return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
  }
  </code></pre>
  
  <p><strong>========Other related information================</strong></p>
  
  <p>My models.py has the Flavor class which is enabled to be voted </p>
  
  <pre><code>secretballot.enable_voting_on(Story) 
  </code></pre>
  
  <p>My ajax call need to pass arguments to the <code>vote()</code> function in views.py at <a href="https://github.com/jamesturk/django-secretballot/blob/master/secretballot/views.py" rel="nofollow">https://github.com/jamesturk/django-secretballot/blob/master/secretballot/views.py</a></p>
  
  <pre><code>def vote(request, content_type, object_id, vote, can_vote_test=None,
           redirect_url=None, template_name=None, template_loader=loader,
           extra_context=None, context_processors=None, mimetype=None):
  </code></pre>
  
  <p>urls.py has</p>
  
  <pre><code>url(r'^flavor/vote/$', 'secretballot.views.vote', name='flavor_vote'),
  </code></pre>
  
  <p>django template flavor_detail.html</p>
  
  <pre><code>&lt;div class="caption flavor" flavor-id="{{ flavor.id }}"&gt;
      &lt;div class="btn btn-default vote"&gt;
         &lt;span class="glyphicon glyphicon-thumbs-up"&gt;&lt;/span&gt;
         Vote
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>