Search code examples
pythondjango

Download an image from image url


I have simple django project and I want to download image from website to my media. Url looks like this: https://i.ytimg.com/vi/Ks-_Mh1QhMc/hqdefault.jpg

How can i do this using python 3.x?


Solution

  • use urllib.request

    import urllib.request as req
    
        imgurl ="https://i.ytimg.com/vi/Ks-_Mh1QhMc/hqdefault.jpg"
    
        req.urlretrieve(imgurl, "image_name.jpg")