Объект Django forms 'str' не имеет атрибута 'get'
ошибка заключается в следующем:
registerform = UserCreationForm(request.POST)
Ошибка здесь! if registerform.is_valid():
class UserCreationForm(forms.ModelForm):
error_messages = {
'password_mismatch': ("The two password fields didn't match."),
"email_missing": ("Please enter email."),
"name_missing": ("Please enter name."),
}
password1 = forms.CharField(label=("Password"),
widget=forms.PasswordInput(attrs={'placeholder': 'Password'}))
password2 = forms.CharField(label=("Password confirmation"),
widget=forms.PasswordInput(attrs={'placeholder': 'Repeat Password'}),
help_text=("Enter the same password as above, for verification."))
first_name = forms.CharField(label=("First Name"), widget=forms.TextInput(attrs={'placeholder': 'First name'}))
last_name = forms.CharField(label=("Last Name"), widget=forms.TextInput(attrs={'placeholder': 'Last name'}))
username = forms.CharField(label=("Username"), widget=forms.TextInput(attrs={'placeholder': 'Username'}))
email = forms.EmailField(label=("Email"), widget=forms.TextInput(attrs={'placeholder': 'Email'}),help_text=('Security is of upmost importance for Glocal. We require email address verification in order to prevent trolling and fake accounts. Please enter your email address below and click on "verify" in the email that we will send you, in order to activate your account.'))
def __init__(self, *args, **kwargs):
super(UserCreationForm, self).__init__(*args, **kwargs)
# remove username
self.fields.pop('username')
class Meta:
model = User
fields = ("username", "email",)
field_order = ['first_name', 'last_name', 'password1', 'password2', 'email']
def clean(self):
cleaned_data = super(UserCreationForm, self).clean()
password1 = cleaned_data["password1"]
password2 = cleaned_data["password2"]
email = cleaned_data["email"]
username = cleaned_data['first_name'] + "." + cleaned_data['last_name']
first_name = cleaned_data['first_name']
last_name = cleaned_data['last_name']
if password1 and password2 and password1 != password2:
raise forms.ValidationError(
self.error_messages['password_mismatch'],
code='password_mismatch',
)
if not email:
raise forms.ValidationError(
self.error_messages['email_missing'],
code="email_missing")
if not first_name or not last_name:
raise forms.ValidationError( self.error_messages['name_missing'], code="name_missing")
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
Я не уверен, что здесь не так. Сбой как-то связан с процедурой .is_valid(), хотя форма отображается как валидная.
/opt/homebrew/lib/python3.9/site-packages/django/core/handlers/base.py, line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) …
Local vars
/Users/adenhandasyde/GitHub/Googlocal/Glocal/views.py, line 1178, in registrations_new
if registerform.is_valid(): …
Local vars
/opt/homebrew/lib/python3.9/site-packages/django/forms/forms.py, line 190, in is_valid
return self.is_bound and not self.errors …
Local vars
/opt/homebrew/lib/python3.9/site-packages/django/forms/forms.py, line 185, in errors
self.full_clean() …
Local vars
/opt/homebrew/lib/python3.9/site-packages/django/forms/forms.py, line 406, in full_clean
self._post_clean() …
Local vars
/opt/homebrew/lib/python3.9/site-packages/django/forms/models.py, line 392, in _post_clean
exclude = self._get_validation_exclusions() …
Local vars
/opt/homebrew/lib/python3.9/site-packages/django/forms/models.py, line 352, in _get_validation_exclusions
field_value = self.cleaned_data.get(field) …
Local vars
Здесь в строке 352 есть что-то о модели формы django.
self.clean_data может возвращать строку.