我尝试使用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
我的代码出了什么问题?
由于
答案 0 :(得分:2)
在为基于类的视图定义URL时,您需要使用as_view
类方法。
url(r'^dracoin/validator/$',Match_view.as_view(),name = 'vista_validador'),