2👍
In django-speak, what you’re referring to as the view is the template. It’s rather confusing!
Update: I see that you define a clean_password2
function but you are checking for fields called new_password1
, new_password2
.
Unless you have a field called password2
, that is the field that your clean method is validating.
The messages for clean_password2
are generated in {{ form.password2.errors }}
, but to me, it sounds like you don’t have a field called password2
.
Change the name of your method to clean_new_password2
.
{% if form.new_password1.errors %}{{ form.new_password1.errors }}{% endif %}
{% if form.new_password2.errors %}{{ form.new_password2.errors }}{% endif %}
Form field cleaning works per field.. you access the errors off the field object.
0👍
Like @Yuji said, use {% if form.non_field_errors %}
in your template.
Now just a bit on usability. Concerning the user registration and password change form, the only non-field errors your can expect will be mismatching passwords, so unlike other forms where your going to print the non-field errors at the very beginning, for these forms it makes sense to print the one non-field error before the two password input fields, possibly wrapping them in a parent that has a red background, to make it more obvious that the values of the two fields are related and that the error concerns the two fields, not the form in general.