django crispy表单中没有显示错误字段?

时间:2014-11-20 20:30:18

标签: django django-forms django-crispy-forms

这是我的表单类:

class VinForm(forms.Form):
    VIN = forms.CharField(min_length=13,max_length=13, label='VIN')

    def __init__(self, *args, **kwargs):
        super(VinForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.form_class = 'form-horizontal col-xs-12 col-md-6 col-lg-5'
        self.helper.label_class = 'col-xs-3 col-md-3 col-lg-3'
        self.helper.field_class = 'col-xs-12 col-md-12 col-lg-12'

        self. helper.layout = Layout(
            Fieldset(
                'Get vehicle info',
                Field('VIN', autofocus=True, placeholder='JN1HJ01F8RT231164'),
            ),
            FormActions(
                Submit('submit', 'get vehicle info'),
            ),
        )

请注意,我没有使用ModelForm,因为没有必要。当我为VIN输入3位数时,它应该显示错误。目前它没有显示任何错误。我该如何解决这个问题?

这是我在模板中的渲染:

{% load crispy_forms_tags %}
   {% crispy form %}

我的观点:

class HomePageView(FormView):
    success_url = '/dashboard/'
    template_name = 'home.html'
    form_class = VinForm

    def get_context_data(self, **kwargs):
        context = super(HomePageView, self).get_context_data(**kwargs)
        context['vehicle_count'] = 1234  #Glucose.objects.count()
        form =  VinForm()
        context['form'] = form
        return context

0 个答案:

没有答案