nem*_*ign 7 python django django-forms
我想在ModelForm中添加一个额外的字段.这似乎很容易,但我收到以下错误:
Django Version: 1.4 pre-alpha SVN-16573
Exception Type: TypeError
Exception Value:
argument of type 'NoneType' is not iterable
Exception Location: /usr/local/lib/django-trunk/django/forms/models.py in construct_instance, line 39
Python Executable: /usr/bin/python
Python Version: 2.6.6
Run Code Online (Sandbox Code Playgroud)
这是代码:
class NodeForm(forms.ModelForm):
password2 = forms.CharField(max_length=20, required=True, widget=forms.PasswordInput())
class Meta:
model = Node
def __init__(self, *args, **kwargs):
super(NodeForm, self).__init__(*args, **kwargs)
# css classes for fields
for v in self.fields:
self.fields[v].widget.attrs['class'] = 'text ui-widget-content ui-corner-all'
def clean(self):
''' Calls parent clean() and performs additional validation for the password field '''
super(NodeForm, self).clean()
password = self.cleaned_data.get('password')
password2 = self.cleaned_data.get('password2')
# password and password2 must be the same
if password != password2:
raise forms.ValidationError('I due campi password non corrispondono.')
Run Code Online (Sandbox Code Playgroud)
我无法修复它.我究竟做错了什么?
应该返回从清理数据clean的方法记录在这里
就是说:
def clean(self):
# perform checks
return self.cleaned_data
Run Code Online (Sandbox Code Playgroud)