I have this in index.html:
{% for item in data %}
<tr>
<td>{{item[0]}}</td>
<td>{{item[1]}}</td>
<td>{{item[2]}}</td>
<td>{{item[3]}}</td>
<td>{{item[4]}}</td>
<td>{{item[5]}}</td>
<td>{{item[6]}}</td>
<td>{{item[7]}}</td>
<td>{{item[8]}}</td>
<td>{{item[9]}}</td>
<td>{{item[10]}}</td>
<td>
<form action="{{ url_for('history') }}" method="POST">
<button type="submit"> History </button>
</form>
</td>
</tr>
{% endfor %}
And this in app.py:
@app.route('/history', methods=['GET', 'POST'])
def history():
return render_template('history.html')
So my webpage has a table with a bunch of rows and each row as a button labeled 'History'. Since right now each button does the same thing and points to history(), how can i distinguish which row of data the original click came from?
You'll have to add the item ID into the HTML form, but you can not display it. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/hidden
Something like the following
<form action="{{ url_for('history') }}" method="POST">
<input id="historicalId" name="historicalId" type="hidden" value="{{item.id}}">
<button type="submit"> History </button>
</form>
Then in flask, you'll need to parse out the request form body
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With