显示图像通过flask / python从HTML连接到HTML [英] display image attach from couchDB in html via flask/python
问题描述
问题是,我只得到这个:
couchdb.http.ResponseBody对象在0x103b9c0b8>返回。
app.py
from flask import Flask,request,render_template,flash ,请求,url_for,重定向
导入couchdb
导入请求
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 =viewportcontent =width = device-width,initial-scale = 1>
< / head>
< body>
< img src ={{doc}}id =imgslot>
< h1 id =h1id> {{doc}}< / h1>
< / body>
< / html>
在我看到@ SHC的答案之前,用我自己的解决方案。
我所做的是检索附件的名称,然后将其追加到URL的末尾,如http:localhost:5984 / dbName / docId / attachmentName。
我把那个URL传递给了html img src,然后它就工作了。谢谢你@SHC的答案。对不起,我没看见它。
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>
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.
这篇关于显示图像通过flask / python从HTML连接到HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!