當前位置: 首頁>>代碼示例>>Python>>正文


Python AnswerForm.add_error方法代碼示例

本文整理匯總了Python中questions.forms.AnswerForm.add_error方法的典型用法代碼示例。如果您正苦於以下問題:Python AnswerForm.add_error方法的具體用法?Python AnswerForm.add_error怎麽用?Python AnswerForm.add_error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在questions.forms.AnswerForm的用法示例。


在下文中一共展示了AnswerForm.add_error方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: QuestionsPage

# 需要導入模塊: from questions.forms import AnswerForm [as 別名]
# 或者: from questions.forms.AnswerForm import add_error [as 別名]
def QuestionsPage(request):
    if request.user.registered:
        if request.user.user_profile.win == True:
            return redirect(reverse('win_page'))
        else:
            if request.method == 'GET':
                try:
                    question = Question.objects.get(current=True)
                except ObjectDoesNotExist:
                    request.user.user_profile.win = True
                    request.user.user_profile.save()
                    return redirect(reverse('win_page'))
                answer_form = AnswerForm()
                return render(request,'Questions/questionspage.html',{"question":question,"answer_form":answer_form})
            elif request.method == 'POST':
                question = Question.objects.get(current=True)
                answer_form=AnswerForm(request.POST,request.FILES)
                if answer_form.is_valid():
                    recieved_file = request.FILES['file']
                    sample_file = open(os.path.join(settings.BASE_DIR,'files/output/'+question.title+".txt"), 'rb')
                    flag = True
                    line1 = recieved_file.readline()
                    
                    line2 = sample_file.readline()
                    while line1 != bytes('#','utf-8') or line2 != bytes('#','utf-8'):
                        print(line1,line2)
                        if line1 != line2:
                            flag = False
                            break
                        line1 = recieved_file.readline()
                        line2 = sample_file.readline()
                    print(flag)
                    sample_file.close
                    if flag:
                        request.user.user_profile.win = True
                        request.user.user_profile.time_counter = int(format(datetime.now(), 'U'))
                        request.user.user_profile.save()
                        return redirect(reverse('win_page'))
                    else:
                        answer_form.add_error('file',"Oops, This is not the answer we expected")
                        return render(request,'Questions/questionspage.html',{"question":question,"answer_form":answer_form})
                else:
                    return render(request,'Questions/questionspage.html',{"question":question,"answer_form":answer_form})
                    
    else:
        return redirect(reverse('register_page'))
開發者ID:hemantjadon,項目名稱:codeGamble,代碼行數:48,代碼來源:views.py


注:本文中的questions.forms.AnswerForm.add_error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。