1

I have json file and it contain

"Product_url": "https://www.amazon.in/Samsung-Galaxy-Storage-Additional-Exchange/dp/B07PQ7CRBH/ref=sr_1_11?keywords=phone&qid=1563166792&s=electronics&smid=A14CZOWI0VEHLG&sr=1-11",

How to get image from this like below one

https://images-na.ssl-images-amazon.com/images/I/71ftMiKUwbL._SL1500.jpg

bishwas
  • 13
  • 3

1 Answers1

0

I understand this question in two ways.

One, if you just want to display the image on a template then simply use the src attribute of the img element and set that URL

Secondly, if you want to pass the image from your views.py to the template then follow the method here - How can I pass an image to a template in Django?

The URL of the image is sufficient. In your relevant views.py method add a request call to the URL and download the image and pass the data as context, example call below.

import requests

url = "https://images-na.ssl-images-amazon.com/images/I/71ftMiKUwbL._SL1500.jpg"
response = requests.get(url)
if response.status_code == 200:
    with open("/Users/apple/Desktop/sample.jpg", 'wb') as f:
        f.write(response.content)
AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35
  • How to get image URL from page is my concern.Sorry, i didn't get in your above answer. – bishwas Oct 01 '20 at 04:35
  • You'd need to scrape the page to obtain the image url, using bs4 or headless selenium. – AzyCrw4282 Oct 01 '20 at 10:33
  • Or also you can use the `Amazon` library to get the image `URL` give the product Id - see this example [here](https://stackoverflow.com/questions/46269803/get-all-image-urls-from-amazon-api) – AzyCrw4282 Oct 01 '20 at 11:47
  • @bishwas Have you solved it? If this answer helped in your problem, please mark it as accepted by clicking the check mark next to the answer. see [here](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) for more information – AzyCrw4282 Oct 04 '20 at 12:32