Last active
October 7, 2018 16:50
-
-
Save ryangmolina/76b0feb4671f79bb6fdd9c9a8aa98fbc to your computer and use it in GitHub Desktop.
Django get image data instead of image url snippet
This file contains hidden or 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
def get_image_data(request, id): | |
person = Person.objects.get(id=id) | |
try: | |
image_data = persion.image.open().read() | |
except FileNotFoundError: | |
raise FileNotFoundError('File not found') | |
content_type = mimetypes.guess_type(person.image.path) | |
return HttpResponse(image_data, content_type=content_type) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment