@
jokaye 好像还是不行
版本信息:django1.3.1 ,python2.7.1
以下是代码:
class TopicForm(forms.Form):
title=forms.CharField(max_length=50,label='标题')
content=forms.CharField(max_length=300,widget=forms.Textarea(),label='内容')
def __init__(self, *args, **kwargs):
super(TopicForm, self).__init__(*args, **kwargs)
self.error_message = u'不超过300字'
def clean_title(self):
title = self.cleaned_data['title']
if len(title) > 50:
raise forms.ValidationError(u'不超过50字')
return title
def clean_content(self):
content = self.cleaned_data['content']
if len(content) > 300:
raise forms.ValidationError(self.error_message)
return content