flask-script

django中,有命令

python manage.py runserver

python manage.py makemigrations

...自定制命令(django如何自定制命令)...

-python manage.py init_db excel文件路径 指定表名

flask启动项目,像djagno一样,通过命令启动

指定版本

复制代码
pip install Flask==2.2.2
pip install Flask_Script==2.0.3

借助于:flask-script 实现

修改代码

复制代码
from flask_script import Manager
manager=Manager(app)     #利用Manager关联app,命令得到管理和使用

if __name__ == '__main__':
    manager.run()         

使用命令启动

复制代码
 python manage.py runserver

#manage.py就是manager.run()的页面

自定制命令

python 复制代码
    #1  相当于位置传参
    @manager.command         
    def custom(arg):
        # 命令的代码,比如:初始化数据库, 有个excel表格,使用命令导入到mysql中
        print(arg)

    #2 复杂一些的自定制命令   相当于关键字传参
    @manager.option('-n', '--name', dest='name')
    @manager.option('-u', '--url', dest='url')
    def cmd(name, url):
        # python run.py cmd -n lqz -u xxx
        # python run.py cmd --name lqz --url uuu
        print(name, url)
相关推荐
知行合一。。。1 小时前
Python--04--数据容器(总结)
开发语言·python
架构师老Y1 小时前
008、容器化部署:Docker与Python应用打包
python·容器·架构
lifewange1 小时前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
GreenTea2 小时前
一文搞懂Harness Engineering与Meta-Harness
前端·人工智能·后端
pluvium272 小时前
记对 xonsh shell 的使用, 脚本编写, 迁移及调优
linux·python·shell·xonsh
2401_827499992 小时前
python项目实战09-AI智能伴侣(ai_partner_5-6)
开发语言·python
PD我是你的真爱粉2 小时前
MCP 协议详解:从架构、工作流到 Python 技术栈落地
开发语言·python·架构
ZhengEnCi2 小时前
P2G-Python字符串方法完全指南-split、join、strip、replace的Python编程利器
python
是小蟹呀^2 小时前
【总结】LangChain中工具的使用
python·langchain·agent·tool
宝贝儿好2 小时前
【LLM】第二章:文本表示:词袋模型、小案例:基于文本的推荐系统(酒店推荐)
人工智能·python·深度学习·神经网络·自然语言处理·机器人·语音识别