为了账号安全,请及时绑定邮箱和手机立即绑定

Flask 将 request.form 值传递给 url_for

Flask 将 request.form 值传递给 url_for

饮歌长啸 2021-06-11 22:08:32
我有一个 Flask 模板,它显示一个页面,其中包含一个dropdown列表owners,一个table包含所有者的输赢记录,以及一个radio在regular赛季记录和playoff记录之间切换的页面。所需的工作流程是:如果通过导航栏导航到页面,它应该默认为/matchup-history/regular。(这有效)否则,无论何时radio切换,它都应该相应地路由。(这不起作用)比赛历史.html{%- extends "base.html" -%}{% block nav_matchups %}active{% endblock %}{%- block content -%}  <form action="{{ url_for('show_matchup_history', matchup_type=request.form['matchup_type']) }}" method="post">    <label>      <select name="owner_id" onchange="this.form.submit()">      {%- for o in owners %}        {%- if request.form['owner_id'] == o['owner_id']|string() %}        <option value="{{ o['owner_id'] }}" selected>{{o['first_name'] + " " + o['last_name'] }}</option>        {%- else %}        <option value="{{ o['owner_id'] }}">{{o['first_name'] + " " + o['last_name'] }}</option>        {%- endif %}      {%- endfor %}      </select>    </label>    {% block matchup_type_radio %}{% endblock %}  </form>  {%- if records|length > 0 %}  <div class="stats-table">    <table>      <tr>        {%- for th in table_headers %}        <th>{{ th }}</th>        {%- endfor %}      </tr>      {%- for r in records %}      <tr>        {%- for cn in column_names %}        <td>{{ r[cn] }}</td>        {%- endfor %}      </tr>      {%- endfor %}    </table>  </div>  {%- endif %}{% endblock -%}比赛历史/regular.html{%- extends "matchup-history.html" -%}{% block matchup_type_radio %}<label><input type="radio" name="matchup_type" value="regular" onclick="this.form.submit()" checked>Regular Season</label><label><input type="radio" name="matchup_type" value="playoffs" onclick="this.form.submit()">Playoffs</label>{% endblock %}比赛历史/playoffs.html{%- extends "matchup-history.html" -%}{% block matchup_type_radio %}<label><input type="radio" name="matchup_type" value="regular" onclick="this.form.submit()">Regular Season</label><label><input type="radio" name="matchup_type" value="playoffs" onclick="this.form.submit()" checked>Playoffs</label>{% endblock %}
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 267 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号