I my current project, my index page show several torrents with a button for each to start or stop the torrent.
I create the page with a form and a loop, so the forms have always the same names. But I need to know which button the user has clicked to know which torrent to stop !
Here is the template :
{% block content %}
<h1>Hello, {{user}} !</h1>
{% for torrent in torrents %}
<form action="/index" method="post" name="torrent">
{{torrent.control.hidden_tag()}}
<p><a href='/torrent/{{torrent.id}}'>{{torrent.name}}</a> is {{torrent.status}} and {{torrent.progress}} % finished. <input type="submit" value="Start / Stop">
</p>
</form>
{% endfor %}
Here is the view :
@app.route('/index', methods = ['GET', 'POST'])
def index():
user = 'stephane'
torrents = client.get_torrents()
# for each torrent, we include a form which will allow start or stop
for torrent in torrents:
torrent.control = TorrentStartStop()
if torrent.control.validate_on_submit():
start_stop(torrent.id)
return render_template("index.html", title = "Home", user = user, torrents = torrents)
So, how do I know which torrent the user want to stop/start ?
hidden_tag
? – Warwick