我有一个测验视图,显示问题列表和文本区域,供学生输入答案。由于我是Django的新手,我想知道从post方法获得学生答案的正确方法是什么?这是我目前的代码:
forms.py
class TakeTestForm(forms.Form):
student_answer = forms.CharField(widget=forms.Textarea, label='')
views.py
class TakeTestFormView(FormView):
def post(self, request, *args, **kwargs):
submit_answer_form = self.form_class(request.POST)
if submit_answer_form.is_valid():
answer_list = request.POST['student_answer'] ?? # TODO: Retrieve list of answers from the form
的index.html
{% for question in qst_data %}
<div id="action-container">
{{ take_test_form.as_p }}
</div>
% endfor %}