[Answer]-Using AJAX in django to delete a row in a table represented by a model

1๐Ÿ‘

โœ…

you can use jquery to easily make an ajax request

as part of the event handler that is triggered by a user clicking โ€˜Xโ€™, you can make a request to your django app.

$.post('/django/url/to/your/view', {idToDelete: 'value'}, function(response) {
  // callback
});

Of coures this is just on the client side. In django you will need to creat a new urls.py entry and create the view logic to handle actually deleteing the id.

It is very important to include a csrf token in your post requests. Django provides step by step on how to do this with ajax requests. https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax

๐Ÿ‘คdm03514

Leave a comment