Jacob Boyer is absolutely right - use ajax:
from flask import jsonify from werkzeug.security import safe_join @app.route("/gallery") def gallery(): images = get_images_from_dir("some/base/path/*.jpg") return render_template("gallery.html", images=images) @app.route("/search/images", methods=["POST"]) def search_images(): glob_path = request.form["image_query"] glob_path = safe_join("/some/base/path", glob_path) return jsonify(images=get_images_from_dir(glob_path))
Then, in your template, just click the appropriate endpoint:
<script> </script>
source share