Created
December 18, 2013 19:55
-
-
Save victorono/8028772 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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