' Match_view'对象没有属性' rindex'

时间:2014-11-07 01:35:16

标签: python django django-forms django-views registration

我尝试使用usercreationform创建一个简单的注册表单,但是我收到了这个错误:

File "/home/draicore/project/multilevel/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_mod_func
  143.         dot = callback.rindex('.')

Exception Type: AttributeError at /
Exception Value: 'Match_view' object has no attribute 'rindex'

这是我的源代码:

views.py:

from django.views.generic import TemplateView,FormView
from .forms import UserForm
from django.core.urlresolvers import reverse_lazy

class Match_view(FormView):
    template_name = 'synopticup/validator.html'
    form_class = UserForm
    success_url = reverse_lazy('vista_validador')

urls.py:

url(r'^dracoin/validator/$',Match_view(),name = 'vista_validador'),

forms.py:

from django import forms
from django.contrib.auth.forms import UserCreationForm

class UserForm(UserCreationForm):
    pass

我的代码出了什么问题?

由于

1 个答案:

答案 0 :(得分:2)

在为基于类的视图定义URL时,您需要使用as_view类方法。

url(r'^dracoin/validator/$',Match_view.as_view(),name = 'vista_validador'),