Python 我在下面发布的数据,我想上传到django模型,并希望将图像链接转换为本地主机链接
获取json对象中的数据,并使用字符串替换来更改url域Python 我在下面发布的数据,我想上传到django模型,并希望将图像链接转换为本地主机链接,python,django,python-3.x,Python,Django,Python 3.x,获取json对象中的数据,并使用字符串替换来更改url域 { "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, m
{
"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"
}
使用JSONField()保存数据。。
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))