【发布时间】:2016-11-25 22:28:25
【问题描述】:
我想使用flask和python从couchdb获取图像附件,然后将图像传递给imgurl.html进行显示。 问题是我只得到这个:
couchdb.http.ResponseBody 对象在 0x103b9c0b8> 返回。
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>
【问题讨论】: