Why would you do that this way? The usual way would be to put your
images into the static files and serve it from there. However, you
should be able to do it that way using base64 encoding of the binary data:
from base64 import b64encode
def my_image(request):
image_data = open("/home/toor/Desktop/certificate/logo.png",
"rb").read()
return render_to_response('myapp/bio.html', {'img':
b64encode(image_data)},
context_instance=RequestContext(request))
After that, you can output your image inside the template by using
<img src="data:image/png;base64,{{ img }}" alt="Embedded image" />
On 06/14/2012 08:15 AM, Satvir Toor wrote:
hello,
i wish to display the image into the browser through a template . I
used the following code to retrieve the image from Disk and send that
data to Html file
def my_image(request):
image_data = open("/home/toor/Desktop/certificate/logo.png", "rb").read()
return render_to_response('myapp/bio.html', {'img':image_data},
context_instance=RequestContext(request))
Now, The image is not availble into the html file that is displaying
in browser, Tell me where I m wrong.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.