Class Based Django Class - DeleteView - How to Disable Verification Request

I'm going to classes. I also use JavaScript to confirm client side deletion. Django DeleteView requires a deletion confirmation template that I don't need.

Is there any easy way to disable confirmation on any deletion in Django?

class EntryDeleteView(DeleteView): model = Entry success_url = reverse_lazy('entry_list') # go back to the list on successful del template_name = 'profiles/entry_list.html' # go back to the list on successful del @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(EntryDeleteView, self).dispatch(*args, **kwargs) 
+4
source share
2 answers

You must make a POST request from clients (using an AJAX or POSTing form). This is because if you allow something to remove GET, your service will be vulnerable to CSRF. Someone will send your administrator an email or something else and you will have problems.

+7
source

DeleteView displays the confirmation page on GET and deletes the object if you use POST or DELETE . If your JS does a POST URL after confirmation, it should work the way you want.

+1
source

Source: https://habr.com/ru/post/1399495/


All Articles