django User.objects.get()报错 raise self.model.DoesNotExist手动处理解决办法
def get(self,request,*args,**kwargs):
if kwargs.get('id'):
try:
inst=JsonModels.objects.get(id=kwargs.get("id"))
ser=SerialJson(instance=inst,many=False)
print("xxxxxxxx",ser.data)
return Response(data=ser.data,status=200)
except JsonModels.DoesNotExist:
return CommonResponse(data={"data":{"message":"NotFound"}},
code=404,msg="fail",status=404)