Skip to content

Instantly share code, notes, and snippets.

@victorono
Created December 18, 2013 19:55
Show Gist options
  • Save victorono/8028772 to your computer and use it in GitHub Desktop.
Save victorono/8028772 to your computer and use it in GitHub Desktop.
# pip install requests
import requests
from django.core.files import File
from django.core.files.temp import NamedTemporaryFile
def save_image_from_url(model, url):
r = requests.get(url)
img_temp = NamedTemporaryFile(delete=True)
img_temp.write(r.content)
img_temp.flush()
model.image.save("image.jpg", File(img_temp), save=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment