在我当前的项目中,我的索引页面显示了几个种子,每个种子都有一个按钮来启动或停止种子。
我使用表单和循环创建页面,因此表单始终具有相同的名称。但我需要知道用户点击了哪个按钮才能知道要停止哪个种子!
这是模板:
{% 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 %}
这是视图:
@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)
那么,我怎么知道用户想要停止/启动哪个种子?