title: Return multiple image files with Flask
body: <p>First I've searched a lot and didn't find a straight forward answer to my question yet.</p>
  
  <p>I'm writing a new program which accepts an image and then find similar images to it and then extract image names from a database. I've created a simple response with the name of these image files as a JSON format with Flask in python3. I need to display these images with its name under it as a web page with a response in Flask. The major problem is the number of images are not fixed and may vary, sometimes it became as 10 and sometimes as 0. Actually, I'm not familiar with Flask or HTML, but I need to do it.
  Here is my sample code which response the image names as an array:</p>
  
  <pre><code>from flask import Flask, jsonify, request, redirect, send_file
  import numpy
  import os
  ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
  
  app = Flask(__name__)
  
  
  def allowed_file(filename):
      return '.' in filename and \
             filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
  
  
  @app.route('/', methods=['GET', 'POST'])
  def upload_image():
      # Check if a valid image file was uploaded
      if request.method == 'POST':
          if 'file' not in request.files:
              return redirect(request.url)
  
          file = request.files['file']
  
          if file.filename == '':
              return redirect(request.url)
  
          if file and allowed_file(file.filename):
              # The image file seems valid! Detect faces and return the result.
              return detect_faces_in_image(file)
  
      # If no valid image file was uploaded, show the file upload form:
      return '''
      &lt;!doctype html&gt;
      &lt;title&gt;Face System&lt;/title&gt;
      &lt;h1&gt;Upload a picture and see if it's a picture of database!&lt;/h1&gt;
      &lt;form method="POST" enctype="multipart/form-data"&gt;
        &lt;input type="file" name="file"&gt;
        &lt;input type="submit" value="Upload"&gt;
      &lt;/form&gt;
      '''
  
  
  def detect_faces_in_image(file_stream):
      ...     #some coding to create the founded_file_names
      out=founded_file_names      #array of desired file names
      return jsonify(out)
  if __name__ == "__main__":
      app.run(host='0.0.0.0', port=5001, debug=True)
  </code></pre>
  
  <p>Thanks.</p>