时间:2021-07-01 10:21:17 帮助过:16人阅读
安装:pip install flask-sqlalchemy
pip install flask-migrate
# 启动文件
from flask_script import Manager,Server from flask_migrate import MigrateCommand,Migrate from rbac import create_app,db app = create_app() manager = Manager(app) migrate = Migrate(app,db) manager.add_command("runserver",Server()) manager.add_command("db",MigrateCommand) if __name__ == ‘__main__‘: manager.run()
# 启动文件启动自动触发
from flask import Flask from config.setting import BaseConfig #导入flask-sqlalchemy from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() from .views.user import user # 导入models中的表 from .model.models import * def create_app(): app = Flask(__name__) app.register_blueprint(user) db.init_app(app) return app
执行命令:
初次:
python manage.py db init
python manage.py db migrate
python manage.py db upgrade
二:(查看)生成当前环境的所有插件
生成当前环境的所有依赖: requirements.txt
pip3 freeze > requirements.txt
生成当前程序的所有依赖: requirements.txt
pip3 install pipreqs
pipreqs ./
flask的orm框架----------Flask-SQLAlchemy应用
标签:comm flask 数据库 reg 启动文件 ros print code 技术