ApprovalForm'对象没有属性' cleaning_data'

时间:2016-05-24 08:54:50

标签: python django django-forms

这是我的forms.py

from django import forms
from .models import Request,Query,Approval
class RequestForm(forms.ModelForm):
      class Meta:
           model = Request
           fields = ('reqtype','priority','sample','description','status')`

这是我在views.py中的观点

def req_detail(request,pk):
    req = get_object_or_404(Request, pk=pk)
    form = ApprovalForm(request.POST or None)
    if request.POST and form.is_valid:
        req.isapp = form.cleaned_data['isapp']
        if req.isapp:
            req.assgto = form.cleaned_data['assgto']
        req.save()
    return render(request,'manage/requestdetail.html',{'req':req,'form': form})`

它给出了错误Cleaned_data在批准表单中没有定义的属性。为什么?

1 个答案:

答案 0 :(得分:0)

问题是form.is_valid应为form.is_valid()。原因是form.is_valid返回的值不是None,它总是计算为True,而且由于函数没有被调用,cleaned_data没有填充验证数据。