wtforms - How to show field label in error message Python WTF -
wtf form :
class replyform(baseform): max_reply_count = integerfield(label=_("max reply count") ,default="10",validators = [v.numberrange(max=10), v.inputrequired(message=_('max reply count required'))]) sleep = integerfield(_("sleep") ,validators = [v.numberrange(min=60), v.inputrequired(message=_('sleep required'))])
wtf generate errors that
["not valid integer value", "number must @ 10."]
is possible generating error messages default this?
["max reply count not valid integer value", "max reply count must @ 10."]
i dont want define messages pass params
v.numberrange(max=10,message=_("max reply count must @ 10."))
i found solution :
class baseform(form): def __init__(self, *args, **kwargs): super(baseform, self).__init__(*args, **kwargs) def allerrors(self): allerrors = list() fieldname,errors in self.errors.iteritems(): m in errors: allerrors.append(getattr(self,fieldname).label.text + " : " + str(m)) return allerrors
example usage :
. . . print wtformobj.allerrors()
Comments
Post a Comment