WTForms getting the errors

前端 未结 4 1384
一个人的身影
一个人的身影 2020-12-09 03:34

Currently in WTForms to access errors you have to loop through field errors like so:

for error in form.username.errors:
        print error

4条回答
  •  春和景丽
    2020-12-09 04:16

    The actual form object has an errors attribute that contains the field names and their errors in a dictionary. So you could do:

    for fieldName, errorMessages in form.errors.items():
        for err in errorMessages:
            # do something with your errorMessages for fieldName
    

提交回复
热议问题