简体   繁体   中英

Remove help_text from django UserCreationForm

I am making registration page but I don't like text under username like : Required 150 characters or fewer. Letters, digits and @/./+/-/_ only Required 150 characters or fewer. Letters, digits and @/./+/-/_ only . or under password: Your password can't be too similar to your other personal information. you get the point pls help,thankyou

I tried to find other questions but they all remove help_text from added field as email, but I need to remove from username,password...

class UserRegisterForm(UserCreationForm):

    email = forms.EmailField()

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

and then i render it in html as crispy form

<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>

try edit class Meta as below::

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

If you just don't want to show them on the page,
You can just get rid of them using css:

 .helptext { display: none; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM