Ver Fonte

树练习的delete接口实现

DYaiu há 4 anos atrás
pai
commit
cb0395f047
1 ficheiros alterados com 8 adições e 0 exclusões
  1. 8 0
      workTtree/views.py

+ 8 - 0
workTtree/views.py

@@ -33,3 +33,11 @@ class SchoolDeptViews(APIView):
         # 不删除该属性会转换json错误
         data.pop('_state')
         return Response(data=data, status=status.HTTP_200_OK)
+
+    def delete(self, request):
+        try:
+            # 当传递的id值不存在数据库或没有传id值直接捕获异常
+            data = SchoolDept.objects.get(id=request.GET.get('id')).delete()
+        except Exception:
+            return Response(data={}, status=status.HTTP_400_BAD_REQUEST)
+        return Response(data=data, status=status.HTTP_200_OK)