gpt4 book ai didi

python - 扩展 SignupForm 类的 allauth 问题

转载 作者:太空宇宙 更新时间:2023-11-03 17:32:46 26 4
gpt4 key购买 nike

我不断发现似乎不起作用的过时解决方案。

我正在尝试将错误消息从英语更改为希伯来语,对于我在 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'

我做错了什么?

最佳答案

您继承自 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',
}

关于python - 扩展 SignupForm 类的 allauth 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31647925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com