Table of Contents

This is a collaboration piece between Real Python and Mr. Nathan Nichols.

Welcome. Last time we added AJAX to our basic Django communication app to better the user experience. The end result is an app that is more responsive and functional to the end user since we eliminated the page refresh.

If you remember, we had a little homework assignment at the end of the tutorial: Your turn. We need to handle some more events. With your new found knowledge of jQuery and AJAX, you get to put these into place. I added code to the final app – which you can download here – that includes a delete link. You just need to add an event to handle the click, which then calls a function that uses AJAX to send a POST request to the back-end to delete the post from the database. Follow the same workflow as I did in this tutorial. We’ll post the answer to this next time.

So, in terms of CRUD, we need to add DELETE capabilities. We’ll use the following workflow:

  1. Setup event handler
  2. Create the AJAX request
  3. Update the Django View
  4. Handle the callback
  5. Update the DOM

Setup Event Handler