O'Reilly logo

Django Essentials by Samuel Dauzon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required