Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我在下面发布的数据,我想上传到django模型,并希望将图像链接转换为本地主机链接_Python_Django_Python 3.x - Fatal编程技术网

Python 我在下面发布的数据,我想上传到django模型,并希望将图像链接转换为本地主机链接

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

获取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, 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))