0

Hello am new with mongoengine. I just want to retrieving an image from mongoengine and display it on a page as http reponse in python. I have added images to database and i printed it in the console and i got the following result:

 <GridFSProxy: 506038485e160077b3efc592>
 genus:m
 family:n
 <GridFSProxy: 5060384a5e160077b3efc595>
 genus:m
 family:n

this is my output when i printed the contents in database.from this i understood that the image got saved into database as objects with ids and now what i want is to display these images into a web page. I use for exampleopen(os.path.join(MEDIA_DIR, u"users/clients.html")) to open a client page. how can i show the image in the client page?

Pravitha V
  • 3,308
  • 4
  • 33
  • 51

1 Answers1

2

Taking the documentation example you can retrieve a file like so:

marmot = Animal.objects(genus='Marmota').first()
photo = marmot.photo.read()
content_type = marmot.photo.content_type

So you can get the content_type and set the headers correctly and yield the photo as the content

Ross
  • 17,861
  • 2
  • 55
  • 73
  • `photo` has the image file which you can stream. `content_type` has the content type so you set headers with it. – Ross Sep 28 '12 at 10:15
  • ross i got the image file path in my console but i want it to get displayed on an html page can u help me with that? – Pravitha V Sep 28 '12 at 10:21