def index(request): latest_question_list = Poll.objects().all() context = {'latest_question_list': latest_question_list} try: question = Poll(question=request.POST['question'], pub_date=timezone.now()) choices = [] for i in range(4): if len(request.POST['answer' + str(i + 1)]) > 0: choices.append(request.POST['answer' + str(i + 1)]) for choice in choices: answer = Choice(choice_text=choice) question.choices.append(answer) question.save() except: print "NOT A POST REQUEST" return render(request, 'polls/index.html', context)