Skip to content

Instantly share code, notes, and snippets.

@ryangmolina
Last active October 7, 2018 16:50
Show Gist options
  • Save ryangmolina/76b0feb4671f79bb6fdd9c9a8aa98fbc to your computer and use it in GitHub Desktop.
Save ryangmolina/76b0feb4671f79bb6fdd9c9a8aa98fbc to your computer and use it in GitHub Desktop.
Django get image data instead of image url snippet
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