我在下面发布的数据,我想上传到Django模型,并想将图像链接转换到我们的本地主机lin

2024-03-29 07:39:38 发布

您现在位置:Python中文网/ 问答频道 /正文

{
    "news_by": "Entertainment ",
    "news_title": "'Sarileru Neekevvaru' teaser: Mahesh Babu is visually pleasing, but Prakash Raj takes the cake again",
    "news_description": "Mahesh Babu is a pleasure to the eye, much like always, and 'Sarileru Neekevvaru' teaser is high on style quotient too, but Prakash Raj will win you over once again",
    "image_link":"https://cdn.dnaindia.com/sites/default/files/styles/third/public/2019/11/22/882305-sarileru-neekevvaru-teaser.jpg"
  }

Tags: thebytitleisbutnewsteaseragain
1条回答
网友
1楼 · 发布于 2024-03-29 07:39:38

获取json对象中的数据,并使用字符串替换来更改url域

import json
j = """{ "news_by": "Entertainment ", "news_title": "'Sarileru Neekevvaru' teaser: Mahesh Babu is visually pleasing, but Prakash Raj takes the cake again", "news_description": "Mahesh Babu is a pleasure to the eye, much like always, and 'Sarileru Neekevvaru' teaser is high on style quotient too, but Prakash Raj will win you over once again", "image_link":"https://cdn.dnaindia.com/sites/default/files/styles/third/public/2019/11/22/882305-sarileru-neekevvaru-teaser.jpg" }"""

l = json.loads(j)
l['image_link'] = l['image_link'].replace('https://cdn.dnaindia.com', 'http://localhost')
print(json.dumps(l))

相关问题 更多 >