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)

  

posted @ 2020-10-17 10:47  不带R的墨菲特  阅读(1267)  评论(1编辑  收藏  举报