title: Django: Passing a csrf token through ajax to an UpdateView 405 method not found error
body: <p>I am creating an FAQ app. In my article detail page I am attempting to implement a vote up system. The goal is to allow a user to vote up an article if they find it useful. I do not want the page to be refreshed when the user clicks the vote up button. I have chosen to use an Ajax call from the template along a url to an UpdateView. </p>
  
  <p>Django needs a csrf token to be passed along. The problem I am encountering is a <code>405 (Method Not Allowed)</code> error. I have verified in my network setting in chrome dev that the csrf token is being generated and assigned in the http header. I think the issue may lay in the view but everything I have tried so far has come up short. Any direction would be helpful.</p>
  
  <p>EDIT UPDATE:</p>
  
  <p>I am using Django 1.10</p>
  
  <p><strong>The Url:</strong></p>
  
  <pre><code>from django.conf.urls import url
  from faq.views import *
  
  urlpatterns = [
      url(r'^ironfaq/$', DashboardView.as_view()),
      url(r'^ironfaq/(?P&lt;slug&gt;[\w-]+)/$', SectionView.as_view()),
      url(r'^ironfaq/(?P&lt;topic_slug&gt;[\w-]+)/(?P&lt;section_slug&gt;[\w-]+)/(?P&lt;pk&gt;\d+)/$',
          ArticleDetailView.as_view(), name="faq-article-detail"),
      url(r'^ironfaq/topic/create/$', TopicCreateView.as_view()),
      url(r'^ironfaq/section/create/$', SectionCreateView.as_view()),
      url(r'^ironfaq/(?P&lt;topic_pk&gt;\d+)/article/create/$', ArticleCreateView.as_view()),
      url(r'^ironfaq/topic/update/(?P&lt;pk&gt;\d+)/$', TopicUpdateView.as_view()),
      url(r'^ironfaq/section/update/(?P&lt;pk&gt;\d+)/$', SectionUpdateView.as_view()),
      url(r'^ironfaq/article/update/(?P&lt;pk&gt;\d+)/$', ArticleUpdateView.as_view()),
      url(r'^ironfaq/topic/delete/(?P&lt;pk&gt;\d+)/$', TopicDeleteView.as_view()),
      url(r'^ironfaq/section/delete/(?P&lt;pk&gt;\d+)/$', SectionDeleteView.as_view()),
      url(r'^ironfaq/article/delete/(?P&lt;pk&gt;\d+)/$', ArticleDeleteView.as_view()),
      url(r'^ironfaq/article/vote/(?P&lt;pk&gt;\d+)$/', ArticleVoteView.as_view()),
  ]
  </code></pre>
  
  <p><strong>The Template Script:</strong></p>
  
  <pre><code>{% block scripts %}
  &lt;script&gt;
  $(document).ready(function(){
      var csrftoken = Cookies.get('csrftoken');
  
      function csrfSafeMethod(method) {
          // these HTTP methods do not require CSRF protection
          return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
      }
      $.ajaxSetup({
          beforeSend: function(xhr, settings) {
              if (!csrfSafeMethod(settings.type) &amp;&amp; !this.crossDomain) {
                  xhr.setRequestHeader("X-CSRFToken", csrftoken);
              }
          }
      });
  
  
      function post_call(vote_data){
          var data = {vote_type: vote_data};
          var id = {{ object.id }};
          $.ajax({
              url: "/ironfaq/article/vote/"+id+"/",
              type: "POST",
              data: data,
          }).done(function() {
             console.log("POST!"); 
          });
      }
  
      var vote_up = "vote_up";
      var vote_down = "vote_down";
  
      var thumbs_up = $('#thumbs_up');
      var thumbs_down = $('#thumbs_down');
  
      thumbs_up.on('click', function(){
          post_call(vote_up)
      });
      thumbs_down.on('click', function(){
          post_call(vote_down)
      });
  });
  &lt;/script&gt;
  {% endblock %}
  </code></pre>
  
  <p><strong>The View:</strong></p>
  
  <pre><code>class ArticleVoteView(UpdateView):
      model = Article
      fields = []
  
      def form_valid(self, form):
          article = form.save(commit=False)
          vote_type = self.request.POST.get('vote_type')
  
          if vote_type == 'vote_up':
              article.vote_up = article.vote_up + 1
              article.save()
          elif vote_down == 'vote_down':
              article.vote_down = article.vote_down + 1
              article.save()
  
          data = {'status': 'success', 'vote_type': vote_type, 'yes_count': article.vote_up, 
                  'total_votes': article.total_votes()}
  
          return HttpResponse(json.dumps(data))
  </code></pre>