<input id="convert_pdf" class="form-control btn btn-primary" value="convert(PDF)" >
模型字段bill_to2
为20.当我尝试发送价值超过20的表单时,我得到:
对于类型字符变化,值太长(20)/异常类型:DataError
而不是表单验证错误。是什么原因?
max_length
查看(来自django.views.generic.edit的标准FormView):
class InviteCandidateForm(forms.Form):
def __init__(self, user, *args, **kwargs):
super(InviteCandidateForm, self).__init__(*args, **kwargs)
self.user = user
if self.user.company.display_bill_to2:
self.fields['bill_to2'] = forms.CharField()
self.fields['bill_to2'].label = self.user.company.bill_to2_label
self.fields['bill_to2'].required = True
self.helper = FormHelper()
self.helper.form_method = 'post'
self.helper.layout = Layout(
Fieldset(
'',
'name',
'email',
'bill_to2',
),
ButtonHolder(
Submit('save', 'Send', css_class='button')
)
)
name = forms.CharField()
email = forms.EmailField()
答案 0 :(得分:0)
我的猜测是你没有说它应该明确验证。这就是为什么它成功通过您的表单并到达模型并且您得到错误。
只需添加max_length
属性即可为您提供帮助:
self.fields['bill_to2'] = forms.CharField(max_length=20)