命令行操作flask
Flask-Script
先安装pip3 install Flask-Script
from sansa import create_app from flask_script import Manager app = create_app() manager = Manager(app) if __name__ == '__main__': manager.run() #命令行执行python manage.py runserver运行
自定义命令
# -*- coding:utf-8 -*- #! /usr/bin/env python # __author__ = 'seven' from sansa import create_app from flask_script import Manager app = create_app() manager = Manager(app) @manager.command def custom(arg): ''' 自定义命令 python manage.py custom 123 :param arg: :return: ''' print(arg) @manager.command def create_all(): ''' python manage.py create_all :return: ''' print('create_all') # from sansa import create_app # from sansa import db # # app = create_app() # # with app.app_context(): # db.create_all() @manager.option('-n', '--name', dest='name') @manager.option('-u', '--url', dest='url') def cmd(name, url): ''' 自定义命令 python manage.py cmd -n laoliu -u www.baidu.com python manage.py cmd --name laoliu --url www.baidu.com :param name: :param url: :return: ''' print(name, url) if __name__ == '__main__': manager.run() #命令行执行python manage.py runserver运行
Flask-Migrate
先安装pip3 install Flask-Migrate
SQLAlchemy中本身不支持在运行过程中修改列,如果要修改,需要把表删了,重建,如果要实现和django里类似于makemigrations,migrate等效果,就可以用这个第三方插件了