我需要帮助。如何处理具有多个输入字段值、同名的表单?只有一次,这实际上是基本问题的形式。。我从https://stackoverflow.com/a/478406/6396981找到的另一个想法是:
relations = request.POST.getlist('relations')
我该怎么处理?目前我是用<input type="radio"...
来做的,但是如果在同一个表单中有相同的名称,那么它当然不能工作。但是如果我使用:<input type="checkbox"...
,答案可以一次检查超过1个问题。。。
可能是这样的:
<input type="radio" name="answer-{{ question.id }}">
我怎样才能把一切都看清楚?
已解决:
在我的测试中:
{% for question in questions %}
<input type="hidden" name="question" value="{{ question.id }}/>
{% for answer in question.get_answers %}
<input type="radio" name="answer-{{ question.id }}" value={{ answer.score }}>
{% endfor %}
{% endfor %}
views.py
questions = request.POST.getlist('question')
answers = [request.POST['answer-{}'.format(q)] for q in questions]
结果是:
['20', '19', '16', '13', '11', '10', '9', '8', '1']
['5', '2', '3', '4', '1', '4', '4', '2', '2']
目前没有回答
相关问题 更多 >
编程相关推荐