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.