hangman
hangman

Reputation: 875

django registration redirection

I have used custom field in django registration form , every thing is working fine but whenever it try to redirect , it shows following error.

I dont know what i missed here.

NoReverseMatch at /accounts/register/
Reverse for 'registration_complete' with arguments '()' and keyword arguments '{}' not found.

I tried following

URL

url(r'^accounts/register/$', register, {'backend': 'registration.backends.default.DefaultBackend','form_class': RegistrationFormEx}, name='registration_register'),

registrationForm.py

from django import forms
from registration.forms import RegistrationForm
from django.utils.translation import ugettext_lazy as _
from registration.models import RegistrationProfile

class RegistrationFormEx(RegistrationForm):
    #ADD ALL CUSTOM FIELDS BELOW
    name=forms.CharField()

models.py

import hashlib
import datetime
import hmac
from django.db import models
from django.contrib.auth.models import User
from ecpCommon.models import StateModel
from ecpCommon.enum import enumauto
from ecpPayments.models import PaymentCard
from registration.signals import user_registered
from apps.ecpUser.models import UserProfile
from apps.ecpMerchant.registrationForm import RegistrationFormEx
from apps.ecpCommon.thumbs import ImageWithThumbsField


class MerchantProfile(StateModel):

    name = models.CharField('Merchant Name', max_length=64)




    def user_created(sender, user, request, **kwargs):
        form = RegistrationFormEx(data=request.POST)
        new_user = User.objects.get(username=request.POST['username'])
        digest=hmac.new(str(request.POST['username'])+str(request.POST['password1']), str(request.POST['password1']),hashlib.sha1).hexdigest()
        new_profile = UserProfile(user=new_user,api_key=digest)
        new_profile.save()
        #now add other fields including password hash as well
        uid = new_profile.id

        merchant_profile = MerchantProfile(user_id=uid,
            create_time=datetime.datetime.now(),
            modified_time=datetime.datetime.now(),
            payment_card_id=uid,
            current_state=1,
            name=request.POST['name'],
             )
        merchant_profile.save()


        return new_user

    user_registered.connect(user_created)

Upvotes: 0

Views: 959

Answers (1)

K Z
K Z

Reputation: 30463

It's likely because of the registration success redirection in your views is redirecting to a URL: registration_complete, that does not exist.

To fix it, you should add a url record similar to the one you have for registration_register

url(r'^accounts/register/$', register, {'backend': 'registration.backends.default.DefaultBackend','form_class': RegistrationFormEx}, name='registration_register'),

that points to the correct url with name=registration_complete.

Upvotes: 2

Related Questions