I am creating cards for every image in a directory using a for loop in html. My goal is to allow users to input a new filename, click submit and image file displayed in the card, will be renamed. I can pass the text input from the html to the flask app, but HOW do I associate the text input with the corresponding image file displayed in the card? I need to know which image the user is attempting to rename. How can I create a variable for the filename in the html for loop to pass across to the python flask route.
{% extends "base.html" %}
{% block title %}NameTag{% endblock %}
{% block content %}
<div class="alert alert-warning" role="alert">
NameTag - This feature allows the user to input NameTags for cropped faces. Once faces are NameTagged, they are added into the Faces database.
</div>
<section class="row">
{% for image in images %}
<div class="card" style="width: 18rem;">
<img src = "{{ url_for('static', filename='nametag/' + image) }}">
<div class="card-body">
<form method="POST">
<input name="text">
<input type="submit">
</form>
</div>
</div>
{% endfor %}
</section>
@app.route("/NameTag")
def name():
images = os.listdir(os.path.join(app.static_folder, "nametag"))
return render_template('nametag.html', images=images)
@app.route('/NameTag', methods=['POST'])
def nametag_form_post():
text = request.form['text']
processed_text = text.upper()
# get image filename from html card and rename file to user text input
return processed_text