Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AttributeError: 'Request' object has no attribute 'DELETE'

I am trying to add permission for deleting an object.

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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      

But I am getting the below error:-

AttributeError: 'Request' object has no attribute 'DELETE'

at below statement:-

 request.DELETE["id"]

Please help me to fix this.

>Solution :

Request objects probably don’t have .DELETE, only .GET and .POST.

If you want the id passed from the url. You can access it with view.kwargs['id']

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading