title: django delete object using AJAX or javascript with confirm
body: <p>hello I want to delete a Django object using AJAX or JavaScript  with confirm message on clicking delete but I don't know how to complete AJAX request.</p>
  
  <p>views.py</p>
  
  <pre><code>def delete(request,id):
      try:
          inta = work.objects.get(pk=id)
          inta.delete()
      except:
          pass
      return HttpResponseRedirect(reverse('home'))
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>url(r'^delete/(?P&lt;id&gt;\d+)/$',views.delete, name='delete')
  </code></pre>
  
  <p>html :</p>
  
  <pre><code>{&amp; for app in apps &amp;}
  &lt;p&gt;{{ app.item0 }}&lt;/p&gt;
  &lt;p&gt;{{ app.item1 }}&lt;/p&gt;
  &lt;p&gt;{{ app.item2 }}&lt;/p&gt;
  &lt;button  data-object-id="{{ app.id }}"&gt;remove&lt;/button&gt;
  {% endfor %}
  
  $('button').on('click', function(){
      var confirmation = confirm("are you sure you want to remove the item?");
      if (confirmation) {
       // execute ajax
          alert('removed');
      }
  })
  </code></pre>