0

django登録フォームでカスタムフィールドを使用しましたが、すべて正常に動作していますが、リダイレクトしようとすると、次のエラーが表示されます。

ここで何を逃したのかわかりません。

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

フォローしてみました

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)
4

1 に答える 1

2

ビューでの登録成功リダイレクトが、registration_complete存在しないURL:にリダイレクトしていることが原因である可能性があります。

これを修正するには、使用しているものと同様のURLレコードを追加する必要がありますregistration_register

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

これは、。で正しいURLを指しますname=registration_complete

于 2012-10-02T07:32:11.767 に答える