ниже очищенные данные из формы регистрации пользователя и появляется пароль2 не в запросе. Не уверен, в чем причина. Я включил форму и просмотр кода ниже. Пожалуйста, помогите, почему отсутствует пароль2.
{
'username': 'xyzabc',
'first_name': 'xyz',
'last_name': 'abc',
'email': 'xyzabc@gmail.com',
'password1': 'kjfhekwjfhekjf',
}
forms.py
class RegistrationForm(UserCreationForm):
username = forms.CharField(widget=forms.TextInput(
attrs={'class': 'form-control','type':'text','name': 'username'}),
label="Username")
first_name = forms.CharField(widget=forms.TextInput(
attrs={'class': 'form-control','type':'text','name': 'first_name'}),
label="First Name")
last_name = forms.CharField(widget=forms.TextInput(
attrs={'class': 'form-control','type':'text','name': 'last_name'}),
label="Last Name")
email = forms.EmailField(widget=forms.TextInput(
attrs={'class': 'form-control','type':'text','name': 'email'}),
label="Email")
password1 = forms.CharField(widget=forms.PasswordInput(
attrs={'class':'form-control','type':'password', 'name':'password1'}),
label="Password")
password2 = forms.CharField(widget=forms.PasswordInput(
attrs={'class':'form-control','type':'password', 'name': 'password2'}),
label="Password (again)")
class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email', 'password1', 'password2']
def clean(self, *args, **kwargs):
cleaned_data = super(RegistrationForm, self).clean()
print(cleaned_data)
if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
raise forms.ValidationError("Passwords don't match. Please try again!")
return self.cleaned_data
views.py
from django.shortcuts import render
from django.contrib.auth.forms import UserCreationForm
from .forms import RegistrationForm
def registerPage(request, *args, **kwargs):
form = RegistrationForm()
register_context = {
'form': form
}
print(register_context)
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
form.save()
return render(request, "register.html", register_context)