如何在postgres中从dict中插入valuekey?

问题描述 投票:0回答:1

我创建了一个数据库,想从valuekey字典中插入链接到一个列表中,看起来像这样。

"images": [{
        "link": "https://images-url.com/images/I/61lYKVLbPZL0._AC_SL1500_.jpg",
        "variant": "MAIN"
    }, {
        "link": "https://images-url.com/images/I/7165NDvwSKL0._AC_SL1500_.jpg",
        "variant": "PT01"
    }]

插入的部分是这样的:

IMAGES = data['product']['images']

psycopg2.ProgrammingError: can't adapt type 'dict'

我想插入图片的链接

python json database postgresql-9.4
1个回答
0
投票

我以这种方式解决:数据=

{
    "product": {
        "images": [{
            "link": "https://images-url.com/images/I/61lYKVLbPZL0._AC_SL1500_.jpg",
            "variant": "MAIN"
        }, {
            "link": "https://images-url.com/images/I/7165NDvwSKL0._AC_SL1500_.jpg",
            "variant": "PT01"
        }]
    }
}

images_list = []
images_t = data['product']['images']
for i in images_t:
  images_list.append(i.get('link'))
IMAGES = images_list
© www.soinside.com 2019 - 2024. All rights reserved.