Django - Style form validation error coming from class based view

Hello. In my project, I have a Generic CreateView to create a model instance (shown below)

class ArticleCreateView(CreateView):
    form_class = ArticleModelForm
    template_name = 'article_create.html'
    success_url = reverse_lazy('article_list')

ArticleModelForm:

class ArticleModelForm(forms.ModelForm):
    class Meta:
        model = Article
        fields = ['title', 'description']

    def clean_title(self):
        data = self.cleaned_data.get('title')

        if len(data) < 4:
            raise forms.ValidationError('Please')

        return data

As you can see, a ValidationError get’s raised when invalid data is posted.

I want to style this error, however when I put {{ form.title.errors }} in my template, and style it, the error is shown twice which is not what I want.

The error is shown in the template anyways without this line of code. Does anybody know how to style the validation error raised in the code shown above? Thanks.

See the section of the documentation on How Errors are Displayed. That should get you pointed in the right direction.

Ken

I can’t find what I need there. Can you suggest another method? Eesa.

The second section in it - Customizing the Error List format shows an example of creating a custom template for rendering errors.

Also, if you look further down in the BoundField attributes, you’ll see what CSS classes are being used for rendering the errors. If the only “styling” you want to do are CSS-related changes, you could just override that class in your CSS for that page.

@KenWhitesell Great! Thanks.