如何在烧瓶响应中返回图像?

2023-12-10

举个例子,这个网址:

http://example.com/get_image?type=1

应该返回一个响应image/gifMIME 类型。我有两个静态.gif images,
如果类型是 1,它应该返回ok.gif,否则返回error.gif。如何在烧瓶中做到这一点?


你用类似的东西

from flask import send_file

@app.route('/get_image')
def get_image():
    if request.args.get('type') == '1':
       filename = 'ok.gif'
    else:
       filename = 'error.gif'
    return send_file(filename, mimetype='image/gif')

寄回ok.gif or error.gif,取决于查询参数的类型。请参阅文档send_file功能request object了解更多信息。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在烧瓶响应中返回图像? 的相关文章