Working with AJAX in the task manager

In this section, we will modify the page that displays the list of tasks for deleting the tasks to be carried out in AJAX. To do this, we will perform the following steps:

  1. Add a Delete button on the task_list page.
  2. Create a JavaScript file that will contain the AJAX code and the function that will process the return value of the AJAX request.
  3. Create a Django view that will delete the task.

We will add the Delete button by modifying the tasks_list.html template. To do this, you must change the for task in task loop in tasks_list as follows:

{% for task in tasks_list %} <tr id="task_{{ task.id }}"> <td><a href="{% url "task_detail" task.id %}">{{ task.title }}</a></td> <td>{{ task.description|truncatechars:25 }}</td> ...

Get Django: Web Development with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.