import iofrom flask import current_app as appfrom flask import send_filefrom myproject import Obj@app.route('/logo.png')def logo(): obj = Obj.objects.get(title='Logo') return send_file(io.BytesIO(obj.logo.read()), attachment_filename='logo.jpg', mimetype='image/jpg')
通过io.BytesIO 从二进制数据获取一个fd.
注意, 必须要有filename或者mimetype之一, 否则会报错.