1
Here’s generally the way to fill the errors
value:
class DocumentForm(forms.Form):
labelled_image = forms.FileField(label='Select the Label image')
def clean_labelled_image(self):
# ... (your validation code here) ...
raise forms.ValidationError('Custom error message here')
By putting the validation in the clean_<name>
function, you can raise a ValidationError
that will be placed in {{form.labelled_image.errors}}
once form.is_valid()
is run.
Source:stackexchange.com