change label of a field in a form

Hi,

I am trying to change the labels of the built-in django form (change password) but i am not sure how to do that?

change-passwors.html

{% extends 'cart/main.html' %}

{% block content %}

<h3>Change Password</h3>
<br/>
<p>Make sure you enter the new password twice to confirm!</p>
<br/>
<form method="post">

	{% csrf_token %}
	{{form}}

	{{ form.non_field_errors }}
	<div class="fieldWrapper">
		{{ form.id_old_password.errors }}
		<label for="{{form.id_old_password}}">Email subject:</label>
		{{ form.subject }}
	</div>
	
	<br/>
	<input type="Submit" name="Send email">

	<br/><br/>
	<ul>
		<li>Your password can’t be too similar to your other personal information.</li>
		<li>Your password must contain at least 8 characters.</li>
		<li>Your password can’t be a commonly used password.</li>
		<li>Your password can’t be entirely numeric.</li>
	</ul>

</form>


{% endblock %}

the id_old_password i got from source code of the page

<input type="password" name="old_password" class="form-control" placeholder="أدخل كلمة المرور الحالية" required="" *id="id_old_password"*>

this is the form:

class PasswordChangingForm(PasswordChangeForm):

	class Meta:
		model = User
		fields = ("old_password","new_password1","new_password2")

	old_password = forms.CharField(widget = forms.PasswordInput(attrs={'class':'form-control', 'type':'password', "placeholder":"أدخل كلمة المرور الحالية"}))
	new_password1 = forms.CharField(max_length=50, widget = forms.PasswordInput(attrs={'class':'form-control', 'type':'password', "placeholder":"أدخل كلمة المرور الجديدة"}))
	new_password2 = forms.CharField(max_length=50, widget = forms.PasswordInput(attrs={'class':'form-control', 'type':'password', "placeholder":"أدخل كلمة المرور الجديدة مرة أخرى"}))

See below:


class Meta:
    model = User
    fields = ("old_password","new_password1","new_password2")
    labels = {
        "old_password":  "a_label",
        "new_password1": "new_pw_label",
        "new_password2": "new_pw_label2",
    }
    widgets = {
        "old_password": forms.PasswordInput(attrs={'class':'form-control', 'type':'password', "placeholder":"أدخل كلمة المرور الحالية"}))
        "new_password1": forms.PasswordInput(attrs={'class':'form-control', 'type':'password', "placeholder":"أدخل كلمة المرور الجديدة"}))
        "new_password2": forms.PasswordInput(attrs={'class':'form-control', 'type':'password', "placeholder":"أدخل كلمة المرور الجديدة مرة أخرى"}))
    }
3 Likes