0

Currently, I am getting the HTTPRssponse using:

def imgResponse(valid_image):
    try:
        with open(valid_image, "rb") as f:
            return HttpResponse(f.read(), content_type="image/jpeg")
    except:
        red = Image.new('RGBA', (1, 1), (255,0,0,0))
        response = HttpResponse(content_type="image/jpeg")
        red.save(response, "JPEG")
        return response

I am not sure how to now display this in my HTML template. What I've tried is to pass it in my context:

context = {"other_context_part": other_context_part, "my_image": my_image}

Then I have the following in my template:

{{ my_image }}

I am generating this image dynamically and it is not static. How do I display my HTTPResponse?

Jerry Zhang
  • 1,352
  • 1
  • 9
  • 20
  • 1
    To show it in a template it must be served somewhere. You will need to save it somewhere and reference that path on your html. – cdvv7788 Nov 16 '15 at 03:03

1 Answers1

0

def imageResponseView(...) .... return response

bind url to this view

show image using <img src = "//url_to_that_view" />

Rizwan Mumtaz
  • 3,875
  • 2
  • 30
  • 31