密码1密码2无法覆盖模型格式django中的标签

密码1密码2无法覆盖模型格式django中的标签,django,django-forms,Django,Django Forms,因此,我使用crispy表单来显示我的注册表视图,因为我想覆盖默认标签。当涉及到密码标签和确认密码标签时,我遇到了一个问题。我根本无法更改,即使在覆盖时,我也无法更改,就像我使用用户名1一样。如果您能提供帮助,我将不胜感激 这是抽象用户模型 class CustomUser(AbstractUser): setor_escolhas = ( ("R", "Revendedora"), ("C", "Conces

因此,我使用crispy表单来显示我的注册表视图,因为我想覆盖默认标签。当涉及到密码标签和确认密码标签时,我遇到了一个问题。我根本无法更改,即使在覆盖时,我也无法更改,就像我使用用户名1一样。如果您能提供帮助,我将不胜感激

这是抽象用户模型

class CustomUser(AbstractUser):
setor_escolhas = (
    ("R", "Revendedora"),
    ("C", "Concessionária"),
)
setor= models.CharField(max_length=1,choices=setor_escolhas, blank=False, null=False)
这是我的登记表:

class UserCadastroForm(UserCreationForm):
email = forms.EmailField()

class Meta:
    model = CustomUser
    fields = ['username', 'email', 'password1','setor', 'password2' ]
    labels={'username':'Usuário','setor':'Setor da sua empresa','password1':'Senha'}
这是我的模板格式

{% extends "APP_IVG/layout.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class= "content-section">
    <form method= "POST">
        {% csrf_token %}
        <fieldset class = 'form-group'>
            <legend class= "border-bottom mb-4"> Junte-se hoje</legend>
            {{ form|crispy }}
        </fieldset>
        <div class = "form-group">
            <button class= "btn btn-outline-info" type= "submit"> Cadastre-se </button>
        </div>      
    </form>
    <div class= "border-top pt-3">
        <small class= "text-muted"> 
            Já tem uma conta? <a class= "ml-2" href = "{% url 'Login' %}"> Clique aqui </a>
        </small>
    </div>  
</div>
{% endblock content %}
{%extends“APP_IVG/layout.html”%}
{%load crispy_forms_tags%}
{%block content%}
{%csrf_令牌%}
Junte se hoje
{{form | crispy}}
地籍
杰特姆·乌马·康塔?
{%endblock内容%}

您可以通过两种方法来完成,在
\uuuuu init\uuuu
方法中重写它

class UserCadastroForm(UserCreationForm):
     def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
          self.fields['password1'].label = 'password 1 label'
          self.fields['password2'].label = 'password 2 label'
或者您可以只覆盖表单字段:

class UserCadastroForm(UserCreationForm):

   password1 = forms.CharField(
        label='password 1 label',
        strip=False,
        widget=forms.PasswordInput(),
        help_text='HELP TEXT',
    )
    password2 = forms.CharField(
        label='password 2 label',
        widget=forms.PasswordInput(),
        strip=False,
        help_text='HELP TEXT',
    )

非常感谢你的帮助