Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def register(request):
- if request.method == 'POST':
- user_form = UserRegistrationForm(request.POST)
- if user_form.is_valid():
- new_user = user_form.save(commit=False)
- new_user.set_password(user_form.cleaned_data['password'])
- # new_user.save()
- return render(request, 'accounts/register_done.html', {'new_user': new_user})
- else:
- user_form = UserRegistrationForm()
- return render(request, 'accounts/register.html', {'user_form': user_form})
- class UserRegistrationForm(forms.ModelForm):
- username = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Логин'}))
- password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Пароль'}))
- password2 = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Повторите пароль'}))
- class Meta:
- model = User
- fields = ('username',)
- def clean_password2(self):
- cd = self.cleaned_data
- if cd['password'] != cd['password2']:
- raise forms.ValidationError('Пароли не совпадают!')
- return cd['password2']
Add Comment
Please, Sign In to add comment