display image attach from couchDB in html via flask/python

后端 未结 2 1492
梦毁少年i
梦毁少年i 2021-01-17 04:55

I\'m tying to get an image attachment from couchdb using flask & python then pass the image to imgurl.html to be displayed. The problem is that I\'m only get this:

2条回答
  •  离开以前
    2021-01-17 05:42

    One option could be to base64 encode the image data returned from couchdb and pass the encoded data as a string to the template where you can render it. E.g.

    img = db.get_attachment('2', 'aboutme.jpg', default=None).read()
    img_b64 = base64.b64encode(img)
    
    def imgurl():
       return render_template('imgurl.html', doc = img_b64)
    

    Then in the template:

    
    

    Another option depending on your security model could be to serve the image directly from couchdb by adding the image url to the image tag, e.g. Getting url for an attachment

提交回复
热议问题