Question

I'm trying to use django-registration in my project, and I have to add two extra fields in registration form. My django version is 1.6.2 and python 2.7.

My urls.py:

from django.conf.urls import patterns, include, url

from registration.views import RegistrationView
from common.forms import UserRegistrationForm
import common.regbackend

urlpatterns = patterns('',
    # accounts
    url(r'^accounts/register/$', RegistrationView.as_view(form_class=UserRegistrationForm),
        {'backend': 'user_profile.backends.RegistrationBackend'},
        name='registration_register'),
    url(r'^accounts/', include('registration.backends.default.urls')),

    # home
    url(r'^$', 'home.views.home', name='home'),
)

My common/models.py:

from django.db import models


class Profile(models.Model):
    key = models.CharField(max_length=100)
    code = models.CharField(max_length=100)

    def __unicode__(self):
        return '%s' % self.key

    class Meta:
        ordering = ['key']
        verbose_name = "Profile"
        verbose_name_plural = "Profiles"

My common/forms.py:

from django import forms
from registration.forms import RegistrationForm


class UserRegistrationForm(RegistrationForm):
    key = forms.CharField(label='Key')
    code = forms.CharField(label='VCode')

And finally, common/regbackend.py

from forms import *
from models import Profile
from common.forms import UserRegistrationForm


def user_created(sender, user, request, **kwargs):
    print 'ok'  # breakpoint here!
    return
    '''
    form = UserRegistrationForm(request.POST)
    data = Profile(user=user)
    data.key = form.data["key"]
    data.code = form.data["code"]
    data.save()
    '''

from registration.signals import user_registered
user_registered.connect(user_created)

When I fill up the form and try to send it I get

NotImplementedError at /accounts/register/

and my app never stops at the breakpoint in common/regbackend.py file.

The traceback ends up here:

/Users/null/.virtualenvs/tools/lib/python2.7/site-packages/registration/views.py in register in this function:

def register(self, request, **cleaned_data):
    """
    Implement user-registration logic here. Access to both the
    request and the full cleaned_data of the registration form is
    available here.

    """
    raise NotImplementedError

I have tried to search for solution (especially this, this and this) but most of them are using django-registration 0.8 and I'm using v1.0 which is completely rewritten and some things are not working as they used to. I have tried to adjust it for v1.0 but still getting this error.
What should I do to get rid of this error? Thanks in advance!

Was it helpful?

Solution

When I fill up the form and try to send it I get NotImplementedError at /accounts/register/

Your urls.py makes it look like you are using a custom registration backend (user_profile.backends.RegistrationBackend). You need to add custom logic for user registration (as the docstring on the register method suggests) to its RegistrationView.

Depending on how your application works, it might make more sense to have your backend inherit from one of the two included registration backends.

my app never stops at the breakpoint

A print statement is not the same as a breakpoint: if the statement had executed, it would have printed "ok" to the console or log, but the application would not have stopped or paused.

I have tried to search for solution (especially this, this and this) but most of them are using django-registration 0.8 and I'm using v1.0 which is completely rewritten and some things are not working as they used to.

It might make more sense for you to migrate away from django-registration. Its maintainer has posted a long essay explaining that django-registration 1.0 has issues, but that he no longer uses it and is not maintaining it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top