AttributeError: 'Request' object has no attribute 'DELETE'
AttributeError: 'Request' object has no attribute 'DELETE'
我正在尝试添加删除对象的权限。
views.py
class DeleteView(APIView):
permission_classes = [IsAllowedDelete]
def delete(self, request, id):
obj = Mymodel.objects.get(id=id)
obj.delete()
return Response({"detail" : "Deleted successfully"}, status.HTTP_204_NO_CONTENT)
urls.py
path('remove/<int:id>', vm.DeleteView.as_view(), name='delete_view'),
permissions.py
class IsAllowedDelete(permissions.BasePermission):
def has_permission(self, request, view):
if request.method == "DELETE":
print('id : ',request.DELETE["id"])
return True
else:
return False
但我收到以下错误:-
AttributeError: 'Request' object has no attribute 'DELETE'
在以下声明中:-
request.DELETE["id"]
请帮我解决这个问题。
请求对象可能没有.DELETE
,只有.GET
和.POST
。
如果您希望从 url 传递 id
。您可以使用 view.kwargs['id']
访问它
我正在尝试添加删除对象的权限。
views.py
class DeleteView(APIView):
permission_classes = [IsAllowedDelete]
def delete(self, request, id):
obj = Mymodel.objects.get(id=id)
obj.delete()
return Response({"detail" : "Deleted successfully"}, status.HTTP_204_NO_CONTENT)
urls.py
path('remove/<int:id>', vm.DeleteView.as_view(), name='delete_view'),
permissions.py
class IsAllowedDelete(permissions.BasePermission):
def has_permission(self, request, view):
if request.method == "DELETE":
print('id : ',request.DELETE["id"])
return True
else:
return False
但我收到以下错误:-
AttributeError: 'Request' object has no attribute 'DELETE'
在以下声明中:-
request.DELETE["id"]
请帮我解决这个问题。
请求对象可能没有.DELETE
,只有.GET
和.POST
。
如果您希望从 url 传递 id
。您可以使用 view.kwargs['id']