class CartList(APIView):
#定义编辑方法
def post(self,request):
username = request.POST.get('username')
# print(username)
idlist = cache.get(username)
sum = len(idlist)
test_dict = {}
#遍历数组
for key in idlist:
#通过key来计算元素个数
test_dict[key] = test_dict.get(key,0) + 1
print(test_dict)
# print(idlist)
for i in idlist:
res = CommoDity.objects.filter(id__in=idlist)
print(type(test_dict))
data = serialize('json',res,ensure_ascii=False)
return Response([test_dict,data,sum])
注:Response内用列表形式进行多数据传递 忘谨记