0

在 html 文件中,我有这段代码,它打印出 golfelement 的信息,例如 golfname、changenamefee、url_1net、url_golfagora、url_juchi。我还得到了 golfelement ID {{golfelement.key().id()}}。有一个按钮1net,如果我点击按钮,它会请求myapp/affiliate

{% for golfelement in displaygolf %}
          <tr>
              <td></td>
              <td>{{ golfelement.golfname }}</td>
              <td>{{ golfelement.changenamefee }}</td>
              <td>
                  <a href="{{golfelement.url_1net}}">1net | </a>
                  <a href="{{golfelement.url_golfagora}}">Golfagora | </a>
                  <a href="{{golfelement.url_juchi}}">Juchi</a>
                  {{golfelement.key().id()}}
                  <form method="LINK" action="{{url_for('myapp/affiliate')}}">
                      <input type="submit" value="1net">
                  </form>
              </td>

          </tr>
          {% endfor %}

单击按钮时,我想发送{{golfelement.key().id()}}到 views.py 中的函数affiliate(request, idnum)

def affiliate(request, idnum):
    golfe = Golf.get_by_id(idnum)
    return render_to_response('myapp/affiliate.html',{'affiliate': golfe})    

请帮我如何修改html文件以发送参数{{golfelement.key().id()}}

4

1 回答 1

1
<form method="GET" action="{{ url_for('myapp.affiliate') }}">
    <input type="hidden" name="idnum" value="{{ golfelement.key().id() }} />
    <input type="submit" value="1net" />
</form>

然后你的观点:

def affiliate(request, idnum=None):
    idnum = int(idnum or request.args.get('idnum'))
    golfe = Golf.get_by_id(idnum)
    return render_to_response('myapp/affiliate.html',{'affiliate': golfe}) 
于 2012-12-04T05:39:40.893 回答