S
S
Sergey Nizhny Novgorod2016-06-14 13:32:17
Django
Sergey Nizhny Novgorod, 2016-06-14 13:32:17

How to customize the registration form in Django?

Hello.
I use a ready-made registration form on my page:

{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Регистрация">

Extended the standard form with the e-mail field: (Although, in fact, I just added it to the form). models.py file
class UserCreationCustomForm(UserCreationForm):
    email = EmailField(required = True)

    class Meta:
        model = User
        fields = ("username", "email", "password1", "password2")

    def clean_password2(self):
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError(
                self.error_messages['password_mismatch'],
                code='password_mismatch',
            )
        return password2

    def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)
        user.set_password(self.cleaned_data["password1"])
        if commit:
            user.save()
        return user

As a result, the form appears with help_text, which I would like to correct. How can I do that?
download?id=yjvcJxDpVS4aDpQoLZy5GJe4AtGk

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
un1t, 2016-06-14
@Terras

Instead of displaying the whole form,
you can display individual fields and customize the form as you like

{{ form.username }}
{{ form.username.errors }}

{{ form.email }}
{{ form.email.errors }}
..

M
Mr_Floppy, 2016-06-16
@Mr_Floppy

class Meta:
    ...
    help_texts = {
        'username': "Подсказка"
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question