对于我做错了什么,我在这里完全不知所措。我正在为 django-registration 编写自定义后端,据我所知,我完全按照说明进行操作。我缺少什么论据来完成这项工作?
这是我的错误信息:
TypeError at /accounts/register/
CustomSignUpBackend() takes exactly 1 argument (0 given)
这是我的回溯:
Environment:
Request Method: GET
Request URL: http://localhost:8000/accounts/register/
Django Version: 1.4.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'api',
'contact',
'lessons',
'mainsite',
'piston',
'registration',
'utils')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "c:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "c:\Python27\lib\site-packages\registration\views.py" in register
178. backend = get_backend(backend)
File "c:\Python27\lib\site-packages\registration\backends\__init__.py" in get_backend
32. return backend_class()
Exception Type: TypeError at /accounts/register/
Exception Value: CustomSignUpBackend() takes exactly 1 argument (0 given)
这是相关的行urls.py
:
url(r'^accounts/register/$', register, {'template_name': 'registration/registration_form.html', 'backend': 'lessons.backends.CustomSignUpBackend', 'form_class': MyRegistrationForm}, name='registration_register'),
最后是自定义后端代码(在课程/后端/ init .py 中):
class CustomSignUpBackend(DefaultBackend):
def register(self, request, **kwargs):
username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
new_user = RegistrationProfile.objects.create_inactive_user(username, email,
password, site)
return new_user