[Answered ]-Django Registration Redux โ€“ How to get error messages to display at correct fields.

2๐Ÿ‘

โœ…

You can show the errors in following way for form non-field types as well as specific field type errors. Consider the example of password_change form that I have used:-

<form method="POST" action="{% url 'account_change_password' %}" class="password_change signup">
            {{form.non_field_errors}}
            {% csrf_token %}
            <p><label for="id_oldpassword">Current Password:</label> <input id="id_oldpassword" name="oldpassword" placeholder="Current Password" type="password" required class="sigup_input"/></p>
            <p>{{form.oldpassword.errors}}</p>
            <p><label for="id_password1">New Password:</label> <input id="id_password1" name="password1" placeholder="New Password" type="password" required class="sigup_input"/></p>
            <p>{{form.password1.errors}}</p>
            <p><label for="id_password2">New Password (again):</label> <input id="id_password2" name="password2" placeholder="New Password (again)" type="password" required class="sigup_input"/></p>
            <p>{{form.password2.errors}}</p>
            <button type="submit" name="action">{% trans "Change Password" %}</button>
        </form>

Notice the use of {{form.field_name.errors}}

I hope you got your answer.

Leave a comment