python与html结合显示本地图片,显示图像通过flask / python从HTML连接到HTML

本文介绍了如何通过Flask应用从CouchDB获取图片附件,并在HTML页面(imgurl.html)上展示。问题在于原始代码只返回了ResponseBody对象。解决方案是获取附件名,然后构造URL,将此URL作为HTML中img标签的src,从而成功显示图片。
摘要由CSDN通过智能技术生成

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'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值