Flask返回图片

Flask返回图片代码

@app.route("/api//status.png")
def tmp_image_status(tmpid):
    online = play.get_tmp_online(str(tmpid))
    if online == True:
        with open("static/images/online/online.png", 'rb') as bites:
            return send_file(
                io.BytesIO(bites.read()),
                attachment_filename='line.png',
                mimetype='image/png'
            )
    else:
        with open("static/images/online/offline.png", 'rb') as bites:
            return send_file(
                io.BytesIO(bites.read()),
                attachment_filename='offline.png',
                mimetype='image/png'
            )

 

 

 

发表回复