title: Ajax URL Not Executing The Correct Function in views.py As Defined in urls.py
body: <p>I am leveraging Ajax for some pie charts but data-ajax-url is not working as intended (or as I thought). Per urls.py, reptibase:item-update should execute the item_update function in my views.py file. item_update never gets executed though and instead the same function associated with the current pages url is executed again.</p>
  <p>Currently, am getting a parsing error because HTML is coming back instead of json. json is returned from my item_update function though.</p>
  <p>item.js</p>
  <pre><code>window.onload = function () {
          console.log(&quot;Child: &quot;, document.getElementById(&quot;piee&quot;))
          var ctx = document.getElementById(&quot;piee&quot;).getContext('2d');
  
          var rep_name = $(&quot;#pie1&quot;).attr(&quot;data-rep-name&quot;)
          var ajax_url = $(&quot;#pie1&quot;).attr('data-ajax-url')
          var _data = []
          var _labels = []
  
          // Using the core $.ajax() method
          $.ajax({
  
              // The URL for the request
              url: ajax_url,
  
              // The data to send (will be converted to a query string)
              data: {
                  name: rep_name
              },
  
              // Whether this is a POST or GET request
              type: &quot;POST&quot;,
  
              // The type of data we expect back
              dataType: &quot;json&quot;,
  
              headers: {'X-CSRFToken': csrftoken},
  
              context: this
          })
              // Code to run if the request succeeds (is done);
              // The response is passed to the function
              .done(function (json) {
  
                  if (json.success == 'success') {
                      var newMale = json.malePerc
                      var newFemale = json.femalePerc
                      console.log(newMale, newFemale)
                      _labels.push(&quot;male&quot;, &quot;female&quot;)
                      _data.push(parseFloat(newMale), parseFloat(newFemale))
                      window.myPie.update()
                      var newUVB = json.uvbPerc
                      var newSize = json.specSize
  
                  } else {
                      alert(&quot;Error: &quot; + json.error);
                  }
              })
              // Code to run if the request fails; the raw request and
              // status codes are passed to the function
              .fail(function (xhr, status, errorThrown) {
                  alert(&quot;Sorry, there was a problem!&quot;);
                  console.log(&quot;Error: &quot; + errorThrown);
                  console.log(&quot;Status: &quot; + status);
                  console.dir(xhr);
                  console.warn(xhr.responseText)
              })
              // Code to run regardless of success or failure;
              .always(function (xhr, status) {
                  //alert(&quot;The request is complete!&quot;);
              });
  
          var config = {
              type: 'pie',
              data: {
                  datasets: [{
                      data: _data,
                      backgroundColor: ['#ff0000', &quot;#0000ff&quot;],
                      label: &quot;Temp&quot;
                  }],
                  labels: _labels,
              },
              options: {
                  responsive: true
              }
          };
  
          console.log(&quot;data&quot;, _data);
          console.log(&quot;config&quot;, config)
          window.myPie = new Chart(ctx, config);
          console.log(&quot;window&quot;, window.myPie)
      }
  </code></pre>
  <p>urls.py</p>
  <pre><code>app_name = 'reptibase'
  urlpatterns = [
      path('', views.index, name='home'),
      path('search', views.reptile_search, name='search'),
      path('add', views.reptile_add, name='add'),
      path('list', views.reptile_list, name='list'),
      path('listD', views.reptile_listDelete, name='listDelete'),
      #path('&lt;int:rep_id&gt;', views.reptile_item, name='item'),
      path('&lt;str:scientific&gt;', views.reptile_itemAlt, name='itemAlt'),
      path('&lt;int:rep_id&gt;,&lt;int:specific_id&gt;', views.reptile_itemAlt_Edit, name='itemAltEdit'),
      path('&lt;str:reptile&gt;,&lt;int:id&gt;', views.comments, name='comments'),
      path('update', views.item_update, name='item-update'),
      path('edit', views.reptile_edit, name='edit'),
  ]
  </code></pre>
  <p>itemAlt.html</p>
  <pre><code>&lt;div class=&quot;pie-chart&quot; id=&quot;pie1&quot; data-rep-name=&quot;{{ reptile.scientific }}&quot;
       data-ajax-url=&quot;{% url &quot;reptibase:item-update&quot; %}&quot;&gt;
      &lt;canvas id=&quot;piee&quot;&gt;&lt;/canvas&gt;
      &lt;div class=&quot;graph-popout&quot;&gt;
          &lt;div class=&quot;data&quot;&gt;
              &lt;p&gt;{{ femalePerc }}% Female, {{ malePerc }}% Male. {{ size }} Individuals&lt;/p&gt;
          &lt;/div&gt;
          &lt;p&gt;&lt;a href=&quot;#&quot;&gt;Report Issue&lt;/a&gt;&lt;/p&gt;
          &lt;p&gt;&lt;a href=&quot;#&quot; class=&quot;share&quot;&gt;Share&lt;/a&gt;&lt;/p&gt;
      &lt;/div&gt;
      &lt;h3&gt;Sex&lt;/h3&gt;
      &lt;div class=&quot;background&quot;&gt;&lt;/div&gt;
      &lt;div id=&quot;slice1&quot; class=&quot;pie-slice&quot;&gt;
          &lt;div class=&quot;pie&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div id=&quot;slice2&quot; class=&quot;pie-slice&quot;&gt;
          &lt;div class=&quot;pie&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div id=&quot;slice3&quot; class=&quot;pie-slice&quot;&gt;
          &lt;div class=&quot;pie&quot;&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>