django - 如何从 django 中的以下数据中仅获取“标题”属性值
问题描述
这是views.py我想从序列化数据中获取'title'属性
视图.py
class CalculatView(views.APIView):
query = CartProduct.objects.latest('id')
serializer = CartProductSerializer(query)
choose_product = serializer.data.get('product')
[sell_id] = choose_product
querye = Product.objects.filter(id = sell_id)
serializere = ProductSerializers(querye, many=True)
choosee = serializere.data
print(choosee)
输出 :
[OrderedDict([('id', 2), ('title', 'Frock'), ('date', '2021-04-22'), ('image', '/media/products/kids2.jpg'), ('marcket_price', 1.2), ('selling_price', 1.2), ('description', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), ('category', OrderedDict([('id', 2), ('title', 'Fashion'), ('date', '2021-04-22')])), ('seller', OrderedDict([('id', 2), ('seller_name', 'CIB - Piliyandala'), ('lat', 6.8018), ('lng', 79.9227), ('date', '2021-04-22')]))])]
解决方案
尝试这个。
title = choosee[0].get('title')
print (title)
推荐阅读
- powershell - 从 Powershell 变量启动 RunAs
- html - Bootstrap 导航栏不会折叠并且没有响应
- r - 如何删除数据框中的行并根据匹配的字符值对数值求和
- reactjs - 已解决-单击时努力为映射数组列表中的每个项目创建特定的模态弹出窗口-React Native
- javascript - Mongoose findById 函数返回奇怪的响应
- c - 从c中的txt文件读取
- c++ - 如何在系统进程中获取用户的当前会话?
- python - 安装本地 python 包时遇到问题
- python - 列不是熊猫数据框的列
- java - 如何在线调用 Rest Api 端点?如何将我的代码放入真实服务器