我在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
请求删除资源?为什么?有人可以提供理由/历史/链接来说明为什么会如此吗?
答案 0 :(得分:0)
它用于django.views.generic.edit.DeleteView
。您的代码来自DeletionMixin
,DeleteView
继承了该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
同时收到get
和post
来删除对象。这就是为什么