Adding css class to field on validation error in django
问题 I am using Django's modelform and its really good. How can I highlight the actual text box (e.g. border:red ) if there is a validation error associated with it. Basically what i want is to add a class (error) if there is a validation error to a field. 回答1: What about defining error_css_class? http://docs.djangoproject.com/en/dev/ref/forms/api/#styling-required-or-erroneous-form-rows? class MyForm(ModelForm): error_css_class = 'error' 回答2: Expanding upon errx's answer. Add the CSS .error input