coding utf-8 from django import forms class MyErrorList forms util Err

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding: utf-8 -*-
from django import forms
class MyErrorList(forms.util.ErrorList):
def __unicode__(self):
return self.as_divs()
def as_divs(self):
if not self: return u''
return u'<div class="errorlist">%s</div>' % ''.join([u'<div class="error">%s</div>' % e for e in self])
class AForm(forms.Form):
abc = forms.CharField()
cde = forms.IntegerField(max_value=20)
form = AForm({}, error_class=MyErrorList)
form.is_valid()
## тут выведется форма нормально, с моим error_class
print form.as_p()
print '-' * 80
# а вот тут уже будет ErrorDict
print type(form.errors)
print '-' * 80
print form.errors