Search code examples
djangodjango-registration

Custom django-registration backend must take exactly one argument


I am at an absolute loss here as to what I am doing wrong. I am writing a custom backend for django-registration, and as far as I can tell I'm following the instructions perfectly. What argument am I missing to make this work?

Here is my error message:

TypeError at /accounts/register/
CustomSignUpBackend() takes exactly 1 argument (0 given)

Here is my traceback:

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)

and here is the relevant line in urls.py:

url(r'^accounts/register/$', register, {'template_name': 'registration/registration_form.html', 'backend': 'lessons.backends.CustomSignUpBackend', 'form_class': MyRegistrationForm}, name='registration_register'),

and finally here is the custom backend code (in lessons/backends/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

Solution

  • def TeacherSignupBackend(arg) should be class TeacherSignupBackend(parentClass)

    functions take arguments ... classes inherit from parent class(es)