현재 내 프로젝트에서 내 인덱스 페이지에는 급류를 시작하거나 중지 할 수있는 버튼이있는 여러 급류가 표시됩니다.플라스크에서 클릭 한 버튼을 아는 방법은 무엇입니까?
양식이 항상 같은 이름을 가지도록 양식과 루프가있는 페이지를 만듭니다. 그러나 나는 사용자가 어떤 torrent를 멈출 지 알기 위해 어떤 버튼을 클릭했는지 알아야합니다!
@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)
그래서, 어떻게 중지 할 사용자를 토런트있는 알고
시작/: 여기{% 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 %}
뷰입니다 : 여기
템플릿입니까?
'hidden_tag'코드를 볼 수 있습니까? –
토런트가 맞습니다. 토렌트마다 양식을 열면 숨겨진 필드에 단순히 정보 해시를 제출할 수 있기 때문에 전체적인 문제는 실제로 존재하지 않습니다. 내 대답은 전체 페이지 또는 목록에 대한 단일 양식을 가정합니다. – jhermann