【发布时间】:2010-11-23 08:58:28
【问题描述】:
我的模板中有以下代码:
<form action="" method="post">{% csrf_token %}
{%for category, category_votes in votes%}
<p>{{category}}: {{category_votes}} <!-- displays as expected -->
<input type="hidden" name="votedCat" value="{{category}}" id={{forloop.counter}}>
<input type="submit" name="upvote" value="Vote for...">
<input type="submit" name="downvote" value="Vote against...">
</p>
{%endfor%}
</form>
变量{{category}} 在渲染时按预期显示,但查看POST 数据,"votedCat" 始终是votes 中的最后一个category 值。
例如,如果votes=[('a',1),('b',2),('c',3)],则无论使用哪个输入按钮提交表单,request.POST['votedCat'] 都会返回'c'。我做错了什么?
【问题讨论】:
标签: python django django-templates