Django: DeleteView + HttpResponseNotAllowed

Viewed 671

I found this DeleteView. Anyone can tell me what return HttpResponseNotAllowed(['POST'])is for? Should I add it to my own DeleteView as well?

class DiscountDelete(AdminPermissionRequiredMixin, DeleteView):
    model = Discount

    def get(self, *args, **kwargs):
        return HttpResponseNotAllowed(['POST'])
2 Answers

With the usual delete view, when you do a GET request you get a confirmation page. Then when you submit the form with a POST request, the object is deleted.

The custom get() method is disabling GET requests. Perhaps it's not needed, because the delete requests are submitted from a different view (e.g. a list view).

We can't tell whether or not you should add this functionality to your delete view. It's up to you.

Related