My goal is a Django application where upon registration, users are able to use the site, but that I prompt them later to verify their email (activate it). I send them an email verification email as they register, and then again if they can't find the email.
I'm using Django 1.7.8
and django-registration-redux
.
Here's my landing page view:
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth import authenticate
from django.contrib.auth import login
from registration import signals
from registration.models import RegistrationManager
from drivers.forms import MyUserCreationForm
def create_registration_profile(user, request, **kwargs):
user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, user)
reg_manager = RegistrationManager()
reg_profile = reg_manager.create_profile(user)
reg_profile.save()
print "Callback reached!"
signals.user_registered.connect(create_registration_profile)
def landing(request):
if request.method == 'POST':
form = MyUserCreationForm(request.POST)
if form.is_valid():
new_user = form.save()
new_user = authenticate(email=form.cleaned_data['email'], password=form.cleaned_data['password1'])
new_user.username = new_user.email # my custom user has no username, just email
signals.user_registered.send(sender='landing', user=new_user, request=request)
login(request, new_user)
return HttpResponseRedirect(reverse("myapp:dashboard"))
else:
print form.errors
else:
form = MyUserCreationForm()
return render(request, "landing.html", {
'registration_form': form,
})
Unfortunately, this fails on the creation of the RegistrationProfile
:
Request Method: POST
Request URL: http://localhost:8000/
Django Version: 1.7.8
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'registration',
'macros',
'myapp',
'debug_toolbar')
Installed Middleware:
(u'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/Users/me/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/me/Code/myapp/myapp_web/myapp_web_project/views.py" in landing
29. signals.user_registered.send(sender='landing', user=new_user, request=request)
File "/Users/me/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
198. response = receiver(signal=self, sender=sender, **named)
File "/Users/me/Code/myapp/myapp_web/myapp_web_project/views.py" in create_registration_profile
16. reg_profile = reg_manager.create_profile(user)
File "/Users/me/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/registration/models.py" in create_profile
115. activation_key=activation_key)
File "/Users/me/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
92. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/me/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/db/models/query.py" in create
370. obj = self.model(**kwargs)
Exception Type: TypeError at /
Exception Value: 'NoneType' object is not callable
Any ideas?