How to return images in flask response?

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

Here is what the above code is Doing:
1. We’re using the @app.route decorator to tell Flask what URL should trigger our function.
2. We’re defining a function, get_image(), which returns the image we want.
3. We’re using the request.args.get() function to get the value of the type parameter from the URL.
4. We’re using the send_file() function to send the image to the browser.