在运行howtotangowith django site第9章中给出的代码时,我在views.py中收到以下错误:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/rango/register/
Django Version: 1.7
Python Version: 2.7.8
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rango')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "C:\Users\Blue\Anaconda\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Blue\code\tango_with_django_project\rango\views.py" in register
78. user_form=UserForm(data=request.POST)
Exception Type: TypeError at /rango/register/
Exception Value: this constructor takes no arguments
UserForm的代码:
class UserForm:
password=forms.CharField(widget=forms.PasswordInput())
class Meta:
model=User
fields=('username','email','password')
!!!! 不知道该怎么解决这个错误请帮忙
答案 0 :(得分:3)
您应该从UserForm
ModelForm
class UserForm(forms.ModelForm):
...