M
M
Maxemp2017-09-11 13:29:37
Django
Maxemp, 2017-09-11 13:29:37

How to edit django registration form?

How can I remove what I highlighted in red?6d7f3879d79247ada16c1ad8d3a278c8.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Gilfanov, 2017-09-11
@Maxemp

Maxemp , in short.
Declare a child form class, inheriting from UserCreationForm.
Override the __init__ method of the child class, you can change anything in it.
In this case, something like this:

class MyUserCreationForm(UserCreationForm):
    def __init__(self, *args, **kwargs):
        super(UserCreationForm, self).__init__(*args, **kwargs)
        self.fields['username'].help_text = ''
        self.fields['password'].help_text = ''

After that, use MyUserCreationForm in the view instead of the standard UserCreationForm.
Another possible option is to redefine the child class not the __init__ method, but the nested Meta class. Looks like this:
class MyUserCreationForm(UserCreationForm):
    class Meta:
        model = User
        help_texts = {
            'password': '',
            'username': '',
        }

But I usually redefined everything through __init__. Yes, and the indication of the model seems to be mandatory, which means an extra import and a little subtlety with a custom user model.

P
popkanosoroga, 2022-03-29
@popkanosoroga

I just made label = '' in forms.py, that is, empty and removed everything

password1 = forms.CharField(label = '',required = True, widget = forms.PasswordInput(attrs = {'placeholder': 'Введите пароль'}))
password2 = forms.CharField(label = '',required = True, widget = forms.PasswordInput(attrs = {'placeholder': 'Повторите пароль'})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question