Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return images in flask response? [duplicate]

Tags:

python

flask

People also ask

How do you send multiple pictures on Flask?

To select multiple files after clicking on browse button you need to hold Ctrl key (Windows OS) on the keyboard and click on the images you want to select for upload. Related Posts: Upload and display an image using Python and Flask.

How do I return an image from Flask to HTML?

To display image on a HTML page with Python Flask, we can pass the image path to the template from the view. Then we call render_template with the template file name, and the user_image argument set to the image path.


You use something like

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')

to send back ok.gif or error.gif, depending on the type query parameter. See the documentation for the send_file function and the request object for more information.