我在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)
答案 0 :(得分:2)
可能是因为您的视图中的注册成功重定向正在重定向到不存在的URL registration_complete
。
要解决此问题,您应该添加类似于registration_register
url(r'^accounts/register/$', register, {'backend': 'registration.backends.default.DefaultBackend','form_class': RegistrationFormEx}, name='registration_register'),
指向带有name=registration_complete
的正确网址。