有一个疑问由于看官网文档也没找出答案。
比如:我的表模型如下
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True, comment='主键,自增')
account = db.Column(db.String(64), unique=True, index=True, comment='账号')
password_hash = db.Column(db.String(128), comment='密码')
name = db.Column(db.String(64), comment='姓名')
status = db.Column(db.Integer, comment='状态,1为启用,2为冻结')
role_id = db.Column(db.Integer, db.ForeignKey('role.id'), comment='所属的角色id')
role = db.relationship('Role', back_populates='users')
created_time = db.Column(db.DateTime, index=True, default=datetime.now)
update_time = db.Column(db.DateTime, index=True, default=datetime.now, onupdate=datetime.now)
使用flask-marshmallow
class UserSchema(ma.Schema):
class Meta:
fields = ("account ", "name ", "status ","role_id ","created_time ")
user_schmema=UserSchema()
@api.route('/', methods=['POST'])
def login_test():
user = Users.query.filter_by(account=admin).first()
return user_schema.dump(user)
最后我想返回的数据是
{
code:1,
message:"成功",
data:{
"account":"admin",
"name":"admin",
"status":1,
"role_id":1,
"create_time":"2021/5/11 12:00:00"
}
}
该怎么设置呢?
现在的情况只能返回以下以信息:
{
"account":"admin",
"name":"admin",
"status":1,
"role_id":1,
"create_time":"2021/5/11 12:00:00"
}