[Django]-Delete View With Confirmation Prompt – Django

0👍

The easiest way is to just overload the get method:

class CompanyDeleteView(LoginRequiredMixin, generic.DeleteView):
    model = Company

    def get(self, request, *args, **kwargs):
        return self.delete(request, *args, **kwargs)

3👍

Use JavaScript to show a pop-up when you click the delete button. In that pop-up, there will be a link to your delete view.
So instead of giving the link in delete button give a confirmation pop-up there and write the link in that pop-up.

<script>
function myFunction() {
  var txt;
  if (confirm("Do you want to delete!")) {
   //go to your delete path
  } else {
  //don't do anything
  }

}
</script>

In your button you can call this function like this

<button onclick="myFunction()">Delete it</button>

Leave a comment