I'm trying to add validation to a filefiled, I used this snippet and it works, but the problem is that it raises an exception when the file extension does not match, but I just want it to show form validation errors, not raising errors.
How can I do that?
1 Answer
Simply replace the raise forms.ValidationError(_('Filetype not supported.')) in line 38 to the action you want to occur when the Filetype is not supported.
Python raise raises an exception, replacing it with a different command will stop python from "raising" that specific exception.
1 Comment
M. Dhaouadi
yes, I'm asking about how to add the error to the form's errors dict?, how can I access the form?
ValidationErrorraised when you callform.is_valid()will be caught and added to the error dict. That's how it's supposed to work. docs.djangoproject.com/en/1.11/ref/forms/api/…