多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
1. 初始化模型 (我们以 `api_1_0` 模块为例进行演示) 在 `api_1_0` 目录下的 `model` 目录下的 ` __init__ `文件录入如下代码 ``` #!/usr/bin/env python3 # -*- encoding: utf-8 -*- from app import db import datetime,time class BaseModel(object):     now_date_time = datetime.datetime.now() + datetime.timedelta(hours=8)     create_time = db.Column(db.DateTime, nullable=False, default=now_date_time, comment='创建时间')      update_time = db.Column(db.DateTime, nullable=False, default=now_date_time, onupdate=now_date_time, comment='更新时间') ``` 2. 在 `api_1_0` 目录下的 `model` 目录下新建 `user.py` 模型,录入一下代码 ``` #!/usr/bin/env python3 # -*- encoding: utf-8 -*- from app import db from . import BaseModel from werkzeug.security import generate_password_hash, check_password_hash import datetime,time class UserModel(BaseModel, db.Model):     __tablename__ = "base_user" id = db.Column(db.BigInteger, comment='pk', primary_key=True) # 用户id     username = db.Column(db.String(50), nullable=False, default='') # 用户名     mobile = db.Column(db.String(11), nullable=False, unique=True) # 手机号     password_hash = db.Column(db.String(128), nullable=False) # 密码     avatar_url = db.Column(db.String(255), nullable=False, default='') # 密码 # 添加 property 装饰器之后,会把函数变为属性,属性名即为函数名 @property def password(self): raise AttributeError("can't read") @password.setter def password(self, origin_password): self.password_hash = generate_password_hash(origin_password) defcheck_password(self, origin_password): return check_password_hash(self.password_hash, origin_password) def to_dict(self): return { "user_id": self.id, "username": self.username, "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"), "update_time": int(time.mktime(self.update_time.timetuple()))  } ``` base_user 表结构