我使用django的get_or_create
将数据保存到postgres
。代码工作正常,但是itemgrp1hd字段保存为('Mobile 5010',),而我只输入了Mobile 5010。有人能解释一下为什么括号和单引号在保存在postgres
中时会出现吗。你知道吗
代码如下:
@api_view(['GET', 'POST', 'PUT', 'DELETE'])
def Post_Items_Axios(request):
data_itemfullhd = request.data['Item Name']
data_itemgrp1hd = request.data['Item Group1']
td_items, created = Md_Items.objects.get_or_create(
cunqid = entity_unqid,
itemfullhd = data_itemfullhd,
# defaults = dict(
# itemgrp1hd = data_itemgrp1hd,
# )
)
# type(request.data['Item Group1'])
# <class 'str'>
td_items.itemgrp1hd = data_itemgrp1hd,
td_items.save()
data = {'data_itemfullhd': data_itemfullhd}
return Response(data)
你必须去掉第15行末尾的逗号。你知道吗
更改''''td_items.itemgrp1hd项目=数据项GRP1HD, td公司_项目.保存()“”
至
''td_items.itemgrp1hd项目=数据项GRP1HD td公司_项目.保存()“”
结尾有一个逗号告诉Python您希望它保存在一个元组中。你知道吗
有关尾随逗号和元组的更多信息,请参见此问题。你知道吗
What is the syntax rule for having trailing commas in tuple definitions?
相关问题 更多 >
编程相关推荐