浏览器是否通过POST请求删除资源?

时间:2018-06-27 07:28:05

标签: django post http-delete

我在django codebase中找到了此代码段:

# Add support for browsers which only accept GET and POST for now.
def post(self, request, *args, **kwargs):
    return self.delete(request, *args, **kwargs)

这是什么意思?浏览器是否通过GET / POST请求删除资源?为什么?有人可以提供理由/历史/链接来说明为什么会如此吗?

1 个答案:

答案 0 :(得分:0)

它用于django.views.generic.edit.DeleteView。您的代码来自DeletionMixinDeleteView继承了该mixin来删除对象。

这是self.delete()代码

def delete(self, request, *args, **kwargs):
    """
    Call the delete() method on the fetched object and then redirect to the
    success URL.
    """
    self.object = self.get_object()
    success_url = self.get_success_url()
    self.object.delete()
    return HttpResponseRedirect(success_url)

您可以在文档(here)中查看有关DeleteView的信息。

基本上,DeleteView同时收到getpost来删除对象。这就是为什么