多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
### 1.定义模型 ``` from exts import db from datetime import datetime class BannersModel(db.Model): __tablename__ = "banners_model" id = db.Column(db.Integer,primary_key=True,autoincrement=True) name = db.Column(db.String(255),nullable=False) image_url = db.Column(db.String(255),nullable=False) link_url = db.Column(db.String(255),nullable=False) priority = db.Column(db.Integer,default=0) create_time = db.Column(db.DateTime,default=datetime.now) ``` ### 2.映射到数据库中 ``` from apps import models as apps_models ``` ``` python manage.py db migrate python manage.py db upgrade ``` ### 3.添加轮播图 ``` @bp.route('/abanner/',methods=['POST']) @login_required def abanner(): form = AddBannerForm(request.form) if form.validate(): name = form.name.data image_url = form.image_url.data link_url = form.link_url.data priority = form.priority.data banner = BannerModel(name=name,image_url=image_url,link_url=link_url,priority=priority) db.session.add(banner) db.session.commit() return restful.success() else: return restful.params_error(message=form.get_error()) ```