Created
October 17, 2016 20:23
-
-
Save eyesee1/1ea8e1b90bfe632cd31f5a90afc0370c to your computer and use it in GitHub Desktop.
Grabbing image data from a URL and saving into Wagtail CMS - example code
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
from io import BytesIO | |
import requests | |
from django.core.files.images import ImageFile | |
from wagtail.wagtailimages.models import Image | |
# event is a model object, substitute your model | |
# filename and title are up to you | |
# in my model, event.event_image is a ForeignKey to wagtailimages.Image | |
response = requests.get(url) | |
image = Image(title=title, file=ImageFile(BytesIO(response.content), name=filename)) | |
image.save() | |
event.event_image = image | |
event.save() |
Thanks a lot, just what I needed!
Thanks, this is very useful:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank!