【发布时间】:2015-10-04 23:49:54
【问题描述】:
我的 web 应用程序中有许多“投票”,它们都显示在同一页面上,但无法弄清楚如何为所有表单设置一个提交(投票)按钮。截至目前,他们对每个问题都有自己的投票按钮,但我希望只有一个底部的按钮来提交所有内容。
我的这个模板的 HTML 代码如下:
{% if latest_question_list %}
{% for question in latest_question_list %}
<h2>{{ question.question.text }}</h2>
<form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
{% for choice in question.choice_set.all %}
<input type="radio" name="choice" id="choice{{ for loop.counter }}" value="{{ choice.id }}" />
<label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
{% endfor %}
<input type="radio" name="choice" value="">Other: <input type="text" />
<br><input type="submit" value="Vote" /></br>
</form>
{% endfor %}
{% else %}
<p>No polls are available.</p>
{% endif %}
有没有简单的方法来做到这一点?我很感激任何帮助!谢谢。
【问题讨论】:
标签: html django django-templates