Andrew Irwin Andrew Irwin - 1 year ago 114
HTML Question

display image attach from couchDB in html via flask/python

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:

couchdb.http.ResponseBody object at 0x103b9c0b8> returned.

from flask import Flask, request, render_template, flash, request, url_for, redirect
import couchdb
import requests

app = Flask(__name__)

couch = couchdb.Server('')

db = couch['test2']

doc = db.get_attachment('2', 'aboutme.jpg', default=None)
print("doc: ", doc)

def index():
return render_template('index.html')

def imgurl():
return render_template('imgurl.html', doc = doc)

def page():

return("Andrew Irwin")
#return render_template('index.html')

if __name__ == '__main__':


<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">

<img src="{{ doc }}" id="imgslot" >

<h1 id="h1id"> {{ doc }} </h1>

Answer Source

Before I saw @SHC's answer I managed to come up with a solution my self. What I did was retrieve the name of the attachment and then append that to the end of a url like i.e "http:localhost:5984/dbName/docId/attachmentName". I passed that url to the html img src and it worked then. Thank you you @SHC for your answer. sorry I didnt see it sooner.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download