Skip to content

Instantly share code, notes, and snippets.

@yxkelan
Created November 2, 2012 06:06
Show Gist options
  • Save yxkelan/3998989 to your computer and use it in GitHub Desktop.
Save yxkelan/3998989 to your computer and use it in GitHub Desktop.
Customizing the error list format Django
# In form.py
from django.forms.util import ErrorList
from django.utils.safestring import mark_safe
class ErrorListMsg(ErrorList):
def __unicode__(self):
return self.as_msg()
def as_msg(self):
if not self: return u''
return mark_safe(u'\n'.join([u'<span class="red">%s</span>' % e for e in self]))
#In view.py
file_form = form_class(request.POST,request.FILES,error_class=ErrorListMsg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment