如何修复“ ErrorDict”对象在Django表单验证中没有属性“ status_code”

时间:2019-07-16 13:56:58

标签: django django-forms

我正在尝试验证表单,但以错误结尾,我试图以一种表单获取两个模型。

views.py:

def ipd (request,patient_id):
    patient = Patient.objects.get(pk=patient_id)
    if request.method=="POST":

        data = dict(request.POST)
        data['patient']=Patient.Patient_id
        formtwo = IpdForm(request.POST)
        if  formtwo.is_valid():
            if formtwo.save():
                return render('ipd_list', messages.success(request, 
'Patient is successfully updated.', 'alert-success'))

            else:
                return render('ipd_list', messages.error(request, 'Data is 
not saved', 'alert-danger'))
        else:
            return formtwo.errors
    else:
        formtwo = IpdForm()
        return render(request, 'newipd.html', {'form2':formtwo 
,'form':patient})

0 个答案:

没有答案