1

I'm trying to load a picture from active directory into a django template.

This is the result :

"b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00\x00\x00\x00\x00\x00\xff\xdb\x00C\x00\x02\x01\x01\x01\x01\..." 

I have seen the PHP method and tried to implement it using python with no success. I also tried the base64.decode, to save it in an image file and convert it using pil then load it, base64.decodebase64, I even tried to convert it using javascript and load it in src but all these methods didn't work, I have read a lot of articles but none helped me.

ANy help would be appreciated.

Amine Messaoudi
  • 2,141
  • 2
  • 20
  • 37
shiko48
  • 23
  • 3

1 Answers1

2

I know that it's old. But if someone struggles with the same problem here's how I did it:

import base64
...
thumbnailPhoto = base64.b64encode(entry.thumbnailPhoto.value).decode("utf-8")

And then in the html template

<img src="data:image/gif;base64,{{ thumbnailPhoto }}">