1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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)
|
More like this
- ExcelResponse by Tarken 4 years, 7 months ago
- get and image object by grillermo 1 year, 3 months ago
- Save image in field by grillermo 1 year, 5 months ago
- ResizeImageField by wim 2 years, 8 months ago
- Amazon S3 Enabled FileField and ImageField (with Boto) by natebeacham 3 years, 2 months ago
Comments
ImportError: No module named requests
вхат!?
#
ImportError: No module named requests
what!?
#
The requests module this script imports http://kennethreitz.com/requests-python-http-module.html
#
pip install requests
#