I am using a custom validator on a model field.
Model field:
html_content = models.TextField(blank=True,
verbose_name=_("HTML content"),
validators=[validate_template_syntax])
Validator:
def validate_template_syntax(source):
try:
Template(source)
except (TemplateSyntaxError, TemplateDoesNotExist) as err:
raise ValidationError(str(err))
However, when the validator error is triggered, it pushes the error to both the django messages framework (messages
) and field.errors
, so in a template if I am rendering other messages alongside a form the error is displayed twice.
How do I restrict the validator to only pushing the error to the field errors context?
As @Melyvn states, check your code! I had overwritten
form_invalid
.