想做一个显示一条通知的请求响应,
def getone(self,request):
try:
oid = int(request.pd.get('id'))
qs = Notice.objects.filter(id = oid).values(
"id", "pubdate", "author", 'author__realname', "title", "content", "status"
)
data = {'ret': 0, 'rec': qs}
return JR(data,safe=False)
except Notice.DoesNotExist:
return JR({
'ret': 1,
'msg': f'id 为`{oid}`的客户不存在'
})
except:
err = traceback.format_exc()
return JR({'ret': 2, 'msg': err})
各种报错:Object of type QuerySet is not JSON serializable;In order to allow non-dict objects to be serialized set the safe parameter to False;'dict' object has no attribute '_meta'等
尝试方法