DRF inside DestroyAPIView examples

Use token authentication, using DestroyAPIView delete, use the delete method

# #删除
# class DeleteBlackList(DestroyAPIView):
#
#     authentication_classes = [UserTokenAuthentications,]
#     def get_object(self, *args, **kwargs):
#         user=self.request.user
#         if user.user_type==1 or  user.user_type==2 or  user.user_type==3 :
#             id=self.kwargs.get('id','')
#             black=model.objects.filter(id=id).first()
#             return black
#         else:
#             return None
#     def delete(self, request, *args, **kwargs):
#         data = {}
#         try:
#             return self.destroy(request, *args, **kwargs)
#         except Exception as e:
#             logger.error(e)
#             data['status'], data['msg'], data['data'] = 404, 'You want to delete the data has been deleted ' , ' you want to delete the data has been deleted ' , 
#              return the Response (the Data)

View source discovery functions to achieve successful return is 204, when the end of the current page does not refresh, delete the deleted data will be reported empty type error. Here try to capture it with an exception

Guess you like

Origin www.cnblogs.com/liangliangzz/p/11236837.html