我通过单选按钮循环以获取所选择选项的值。但是,每当未选择选项时,我都会收到此错误。如何将取消选择选项发送给 NULL 或False。
try:
choice_pk = [request.POST['choice_pk{}'.format(q)] for q in question_pk]
except MultiValueDictKeyError:
choice_pk = False
if request.method == 'POST':
question_pk = request.POST.getlist('question_pk', False)
choice_pk = [request.POST['choice_pk{}'.format(q)] for q in question_pk]
'''
try:
choice_pk = [request.POST['choice_pk{}'.format(q)] for q in question_pk]
except MultiValueDictKeyError:
choice_pk = False
'''
#print(marks_obtainable.marks_obtained)
#zipped = zip(question_pk, choice_pk)
with transaction.atomic()