在赋值时给用户的password加密
class User(db.Model):
#__tablename__ = 'user1'
id = Column(Integer, primary_key=True)
nickname = Column(String(24), nullable=False)
_password = Column('password', String(64)) # 重新定义字段为password
phone_number = Column(String(18), unique=True)
email = Column(String(50), unique=True, nullable=False)
confirmed = Column(Boolean, default=False)
beans = Column(Float, default=0)
send_counter = Column(Integer, default=0)
receive_counter = Column(Integer, default=0)
wx_open_id = Column(String(50))
wx_name = Column(String(32))
@property
def password(self):
pass
@password.setter
def password(self, raw):
self._password = generate_password_hash(raw)