gpt4 book ai didi

python - "object got multiple values for keyword argument"使用字典写数据库时

转载 作者:太空宇宙 更新时间:2023-11-04 09:05:54 24 4
gpt4 key购买 nike

我有一个包含以下字段的 Django 模型:citycountry_namecountry_code

我有一个字典,它有超过 8 个键值对;我只想使用 3 并写入数据库。

但是我得到一个错误

ModelBase 对象获得关键字参数“country_code”的多个值

我的代码:

dicty = {
'city': u'Mountain View', 'continent_code': u'NA', 'region': u'CA',
'charset': 0, 'area_code': 650, 'longitude': -122.05740356445312,
'country_code3': u'USA', 'latitude': 37.4192008972168, 'postal_code': u'94043',
'dma_code': 807, 'country_code': u'US', 'country_name': u'United States'
}

m = Logger(city='city',country_name='country_name',country_code='country_code',**dicty)
m.save()

最佳答案

您正在为 country_code 传递两个参数:

m = Logger(city='city', country_name='country_name',
country_code='country_code', **dicty)
# ^ here ^ and in here

所以你得到了 country_code = "country_code" country_code = u"US"。如果您只想传递字典中的三个值,请执行以下操作:

m = Logger(city=dicty['city'], country_name=dicty['country_name'],
country_code=dicty['country_code'])

关于python - "object got multiple values for keyword argument"使用字典写数据库时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20866693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com