首页 > 解决方案 > 从 django UserCreationForm 中删除 help_text

问题描述

我正在制作注册页面,但我不喜欢用户名下的文字,例如 : Required 150 characters or fewer. Letters, digits and @/./+/-/_ only。或密码: Your password can't be too similar to your other personal information. 你明白了,请帮助,谢谢

我试图找到其他问题,但他们都从添加的字段中删除了 help_text 作为电子邮件,但我需要从用户名、密码中删除......

class UserRegisterForm(UserCreationForm):

    email = forms.EmailField()

    class Meta:
        model = User
        fields = ['username', 'email' , 'password1', 'password2']

然后我将它以 html 的形式呈现为酥脆的形式

<form method="POST">
    {% csrf_token %}

    <fieldset>
        <legend class="hello4">
               <i>Join Today</i>
        </legend>
<div >
{{form|crispy}}

</div>
    </fieldset>
    <div>
    <button type="submit" class="btn btn-light">Sign Up</button>
    </div>


</form>

标签: pythondjango

解决方案


尝试编辑类 Meta 如下::

class Meta:
        model = User
        fields = ['username', 'email' , 'password1', 'password2']
        help_texts = {
            'username': None,
            'password1': None,
            'password2': None,
        }

推荐阅读