从Django UserCreateForm移除help_text

从Django UserCreateForm移除help_text,第1张

从Django UserCreateForm移除help_text

您可以在以下位置

help_text
字段设置为“无”
__init__

from django.contrib.auth.forms import UserCreationFormfrom django import formsclass UserCreateForm(UserCreationForm):    email = forms.EmailField(required=True)    def __init__(self, *args, **kwargs):        super(UserCreateForm, self).__init__(*args, **kwargs)        for fieldname in ['username', 'password1', 'password2']: self.fields[fieldname].help_text = Noneprint UserCreateForm()

输出

<tr><th><label for="id_username">Username:</label></th><td><input id="id_username" type="text" name="username" maxlength="30" /></td></tr><tr><th><label for="id_password1">Password:</label></th><td><input type="password" name="password1" id="id_password1" /></td></tr><tr><th><label for="id_password2">Password /confirm/iation:</label></th><td><input type="password" name="password2" id="id_password2" /></td></tr><tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr>

如果您进行了太多更改,在这种情况下,最好覆盖字段,例如

class UserCreateForm(UserCreationForm):    password2 = forms.CharField(label=_("Whatever"), widget=MyPasswordInput

但对于您而言,我的解决方案将非常有效。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5617025.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存