我一直在寻找过时的解决方案,而这些解决方案似乎并不奏效。
我正在尝试将错误消息从英语更改为希伯来语,对于我在django-allauth的网站,我没有检查他们是否有任何翻译,因为无论如何我想自己编写。
我尝试使用以下代码更改重复的电子邮件错误。
forms.py
from allauth.account.forms import SignupForm
class CustomSignupForm(SignupForm):
def raise_duplicate_email_error(self):
raise forms.ValidationError("שם משתמש כבר קיים עם כתובת אימייל")
base.py(基本设置文件)
SOCIALACCOUNT_FORMS = {
'signup': 'website.forms.CustomSignupForm',
}
导致以下错误:
__init__() got an unexpected keyword argument 'sociallogin'
回溯:
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/views/generic/base.py" in view
71. return self.dispatch(request, *args, **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/socialaccount/views.py" in dispatch
38. return super(SignupView, self).dispatch(request, *args, **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/account/views.py" in dispatch
68. **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/account/views.py" in dispatch
151. **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/views/generic/base.py" in dispatch
89. return handler(request, *args, **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/views/generic/edit.py" in get
205. form = self.get_form()
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/views/generic/edit.py" in get_form
74. return form_class(**self.get_form_kwargs())
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/account/forms.py" in __init__
289. super(SignupForm, self).__init__(*args, **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/account/forms.py" in __init__
223. super(BaseSignupForm, self).__init__(*args, **kwargs)
Exception Type: TypeError at /accounts/social/signup/
Exception Value: __init__() got an unexpected keyword argument 'sociallogin'
我做错了什么?
答案 0 :(得分:1)
您继承自 allauth.account.forms.SignupForm ,但在 SOCIALACCOUNT_FORMS 设置中使用它,该设置适用于社交帐户。您的代码应如下所示:
网站/ forms.py 强>
from allauth.socialaccount.forms import SignupForm
class CustomSignupForm(SignupForm):
def raise_duplicate_email_error(self):
raise forms.ValidationError("שם משתמש כבר קיים עם כתובת אימייל")
<强> settings.py 强>
SOCIALACCOUNT_FORMS = {
'signup': 'website.forms.CustomSignupForm',
}
答案 1 :(得分:0)
You need to overwrite the __init__()
method and define sociallogin
as parameter, which then will not be passed to the __init__()
method of the super class.
Like this:
def __init__(self, sociallogin=None, *args, **kwargs):
super().__init__(*args, **kwargs)