Flask self.errors.append() - AttributeError: 'tuple' object has no attribute 'append' Flask self.errors.append() - AttributeError: 'tuple' object has no attribute 'append' flask flask

Flask self.errors.append() - AttributeError: 'tuple' object has no attribute 'append'


The tuple objects cannot append. Instead, convert to a list using list(), and append, and then convert back, as such:

>>> obj1 = (6, 1, 2, 6, 3)>>> obj2 = list(obj1) #Convert to list>>> obj2.append(8)>>> print obj2[6, 1, 2, 6, 3, 8]>>> obj1 = tuple(obj2) #Convert back to tuple>>> print obj1(6, 1, 2, 6, 3, 8)

Hope this helps!


Just came across this myself. I think a better answer to your question is that you should validate the elements before you add errors to them. The validation process sets the error field to a list and if you change it before you validate fields it will be written over when you validate.

So override the validate method of your form, call the parent validate method then run your email_unique method in that.

Then you can remove the email_unique from the view since it will be part of your validate_on_submit


tuples are immutable types which means that you cannot splice and assign values to them. If you are going to be working with data types where you need to add values and remove values, use list instead:

>>> a = (1,2,3)>>> a.append(2)AttributeError: 'tuple' object has no attribute 'append'>>> b = [1,2,3]>>> b.append(2)[1,2,3,2]