我目前的项目,我的索引页面显示了几个种子,每个种子都有一个按钮,用于启动或停止洪流。如何知道我在烧瓶中点击了哪个按钮?
我使用窗体和循环创建页面,因此窗体始终具有相同的名称。但我需要知道用户点击了哪个按钮才能知道哪个torrent停止!
这里是模板:
{% 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)
所以,我怎么知道哪个洪流用户想要停止/启动?
我们可以看到'hidden_tag'的代码吗? –
托马斯是正确的,因为你打开一个表格每个洪流整个问题是真的不存在,因为你可以简单地提交信息哈希在一个隐藏的领域。我的答案假设整个页面或列表的单一表单。 – jhermann