0

我只是想将视图映射到 中的路径urls.py,但是当我尝试它时会引发此错误:

Registration didn't return an HttpResponse object

网址.py

urlpatterns = patterns('',
    (r'^Register/$', Registration),
    (r'^Newuser/$', ProcessRegistration),
)

视图.py

def Registration(request):
    RegForm = RegistrationForm(request.POST or None)
    if request.method == 'POST':
        if RegForm.is_valid():
            clearUserName = RegForm.cleaned_data['userNm']   
            clearPass = RegForm.cleaned_data['userPass']
            RegForm.save()
            try:
                return HttpResponseRedirect('/Newuser/?userNm=' + clearUserName)
            except:
                raise ValidationError(('Invalid request'), code='300')    ## [ TODO ]: add a custom error page here.
    else:
        RegForm = RegistrationForm()

        return render(request, 'VA/reuse/register.html', {
            'RegForm': RegForm 
        })

def ProcessRegistration(request):
    clearUserName = request.GET.get('userNm')
    return HttpResponse("Wee")

当我访问时/Register,它会引发上述错误。

知道为什么它不起作用吗?它正在返回一个响应Wee

4

1 回答 1

0

validators=[]for在我的models.pyuserNm中搞砸了。我正在做:

  class Client(models.Model):
        userNm = models.EmailField(verbose_name="Email",max_length=50,unique=True,validators=[RegexValidator('^\w{6,50}$','format: invalid username','Invalid Entry')])
        userPass = models.CharField(verbose_name="Password", max_length=50)  

我将userNm声明更改为:

userNm = models.EmailField(verbose_name="Email",max_length=50,unique=True) 
于 2013-08-20T02:29:32.677 回答