title: Calling Django View from Ajax
body: <p>I'm using Ajax (along with Django) to perform some action on button click. I successfully call the javascript function but I can't call the Django view. There are no errors but the print statement in my view doesn't print...?</p>
  
  <p>urls.py</p>
  
  <pre><code>urlpatterns = patterns('polls.views',
      url(r'^request_access/$', 'request_access',
          name='request_access'),
  )
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def request_access(request):
      print("DJANGO VIEW")
      if request.method == "POST":
          print("DATA: ", request.POST.get('request_data'))
          return HttpResponse(
              json.dumps(response_data),
              content_type="application/json"
          )
  </code></pre>
  
  <p>template.html</p>
  
  <pre><code>&lt;button class="btn btn-green btn-sm" onclick="request_access(this)" id="{{ data }}"&gt;&lt;i class="fa fa-plus"&gt;&lt;/i&gt; Join Group&lt;/button&gt;
  </code></pre>
  
  <p>javascript.js</p>
  
  <pre><code>function request_access($this){
      console.log("button clicked");
      var request_data = $this.id;
      console.log("data: " + request_data);
      $.post({
          url: "request_access/",
          data : { request_data: request_data},
          success : function(json) {
              $("#request-access").hide();
              console.log("requested access complete");
          }
      })
  }
  </code></pre>