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

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -