【问题标题】:Remove help_text from django UserCreationForm从 django UserCreationForm 中删除 help_text
【发布时间】:2019-08-12 16:44:02
【问题描述】:

我正在制作注册页面,但我不喜欢用户名下的文字,例如: 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>

【问题讨论】:

  • 您能否准确判断您是只想删除文本,还是也禁用验证逻辑?

标签: python django


【解决方案1】:

尝试如下编辑类 Meta::

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

【讨论】:

    【解决方案2】:

    如果您只是不想在页面上显示它们,
    您可以使用 css 摆脱它们:

    .helptext {
        display: none;
    }

    【讨论】:

      猜你喜欢
      • 2012-10-23
      • 2019-01-20
      • 2012-12-27
      • 2011-11-23
      • 2015-02-09
      • 1970-01-01
      • 2011-10-04
      • 2018-03-01
      • 1970-01-01
      相关资源
      最近更新 更多