class BaseRegisterForm(UserCreationForm):
username = forms.CharField(label='Имя пользователя',
widget=forms.TextInput(
attrs={'class': 'form-control',
'placeholder': 'Введите имя пользователя'}))
email = forms.EmailField(label='Электронная почта',
widget=forms.EmailInput(
attrs={'class': 'form-control',
'placeholder': 'Введите Email'}))
password1 = forms.CharField(label='Пароль',
widget=forms.PasswordInput(
attrs={'class': 'form-control',
'placeholder': 'Введите пароль'}))
password2 = forms.CharField(label='Подтверждение пароля',
widget=forms.PasswordInput(
attrs={'class': 'form-control',
'placeholder': 'Подтвердите пароль'}))
class Meta:
model = User
fields = ["username", "email", "password1", "password2"]
class BaseRegisterView(CreateView):
model = User
form_class = BaseRegisterForm
success_url = '/'
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated:
return redirect('redirect')
return super().get(request, *args, **kwargs)
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Продолжить">
</form>
path('signup/', BaseRegisterView.as_view(template_name='sign/signup.html'), name='signup')