Probably a poor question, but I\'m using Django\'s UserCreationForm (slightly modified to include email), and I would like to remove the help_text that Django automatically
I had a similar issue. Based on one of the comments, here is the solution after reading the documentation.
class UserCreateForm(UserCreationForm):
password1 = forms.CharField(label='Enter password',
widget=forms.PasswordInput)
password2 = forms.CharField(label='Confirm password',
widget=forms.PasswordInput)
class Meta:
model=User
fields=("username","email","first_name",
"last_name","password1","password2")
help_texts = {
"username":None,
}
Basically what we are trying to do is over-ride the automated setting by re-creating the password fields for our new class form.
Just go to UserCreationForm and make the required changes.
very simple hold control button on your keyboard and ckick on UserCreationForm you will get the UserCreationForm make the required changes as per your need and save it. as i did it for me in the below example i commented the Help Content.
error_messages = {
'password_mismatch': _("The two password fields didn't match."),
}
password1 = forms.CharField(
label=_("Password"),
strip=False,
widget=forms.PasswordInput,
# help_text=password_validation.password_validators_help_text_html(),
)
password2 = forms.CharField(
label=_("Password confirmation"),
widget=forms.PasswordInput,
strip=False,
help_text=_("Enter the same password as before, for verification."),
)
Or just iterate through form fields and omit to ouput "field.help_text"
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }} {{ field }}
<!--
{% if field.help_text %}
<p class="help">{{ field.help_text|safe }}</p>
{% endif %}
-->
</div>
{% endfor %}
Django doc: https://docs.djangoproject.com/en/3.0/topics/forms/#looping-over-the-form-s-fields
Another, cleaner option is to use help_texts dictionary in class Meta. Example:
class UserCreateForm(UserCreationForm):
...
class Meta:
model = User
fields = ("username", "email", "password1", "password2")
help_texts = {
'username': None,
'email': None,
}
More info in here: https://docs.djangoproject.com/en/1.11/topics/forms/modelforms/#overriding-the-default-fields
Works perfect for username and email, but doesn't work for password2. No idea why.
You can add css class to registration_form.html file like this.
<style>
.helptext{
visibility: hidden;
}
</style>
Simple CSS solution.
<style>
#hint_id_username, #hint_id_password1 {
display: none;
}
</style>
When the forms render inspect the page source code and you will see an id for each help text. Such as hint_id_username
for each form field. Use the above CSS to hide the text.