Django forms templates: Simple question
{{ userForm.username }}
<span class="helptext">{{ userForm.username.help_text }}</span>
If the form is submitted and the value is "empty", then it would show in error_messages the required key, in this case "This field is required", but I want to add an extra class to the span if the error type is required.
So, expample when the user submits the form with an empty value:{{ userForm.username }}
<span class="helptext{% if userForm.username.errors.required %} required{% endif %}">{{ userForm.username.help开发者_如何转开发_text }}</span>
Or something like that, hope you understand guys, thanks!
This should be doable using:
{% if field.errors %}
and
{% if field.field.required %}
Check this post for some general infos on this.
精彩评论