Answer the question
In order to leave comments, you need to log in
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="Регистрация">
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
Answer the question
In order to leave comments, you need to log in
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 }}
..
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question