Andrew Irwin Andrew Irwin - 4 days ago 6
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.

app.py

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

app = Flask(__name__)

couch = couchdb.Server('http://127.0.0.1:5984/')

db = couch['test2']

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

@app.route('/')
def index():
return render_template('index.html')


@app.route('/imgurl/')
def imgurl():
return render_template('imgurl.html', doc = doc)


@app.route('/page/')
def page():

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

if __name__ == '__main__':
app.run()


test.html

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

</head>
<body>
<img src="{{ doc }}" id="imgslot" >

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

Answer

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.

Comments