当前位置:网站首页>Talking about Flask_script
Talking about Flask_script
2022-08-09 08:02:00 【scwMason】
Reference Articlehttps://flask-script.readthedocs.io/en/latest/p>
Concept
Flask_script is an interactive command-line tool for Flask.It is convenient for interactive debugging and script execution.That is to say, it is convenient to debug a function in each file directly in the terminal by means of the command line. Generally, there are three methods.
Method 1 Create a Command subclass
from flask_script import Manager,Server,Commandfrom flask import Flaskapp=Flask(__name__)manager=Manager(app)class Hello(Command):'hello world'def run(self):print("hello world")manager.add_command('hello',Hello())manager.add_command("runserver",Server())if __name__=='__main__':manager.run()
>>python demo1.py hello>>hello world
python demo1.py runserver* Serving Flask app "demo1" (lazy loading)* Environment: productionWARNING: Do not use the development server in a production environment.Use a production WSGI server instead.* Debug mode: off* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
runserver is equivalent to app.run()
Method 2 Use the @command symbol of the Command instance
from flask_script import Manager,Server,Commandfrom flask import Flaskapp=Flask(__name__)manager=Manager(app)@manager.commanddef hello():'hello world'print('hello world')if __name__=='__main__':manager.run()
Method 3 Use the @option modifier of the Command instance
from flask_script import Managerfrom debug import appmanager = Manager(app)@manager.option('-n', '--name', dest='name', help='Your name', default='world') #The command can use either -n or --name,dest="name" The name of the command entered by the user is passed as a parameter to the name in the [email protected]('-u', '--url', dest='url', default='www.csdn.com') #The command can use either -u or --url,dest="url" The url of the command entered by the user is passed as a parameter to the url in the functiondef hello(name, url):'hello world or hello 'print 'hello', nameprint urlif __name__ == '__main__':manager.run()
It works as follows:
python manager.py hello
>hello world
>www.csdn.com
python manager.py hello -n sissiy -u www.sissiy.com
> hello sissiy
>www.sissiy.com
python manager.py hello -name sissiy -url www.sissiy.com
> hello sissiy
>www.sissiy.com
边栏推荐
- Redis(七) 主从复制(二)哨兵模式
- “互联网+”大学生创新创业大赛经历
- 环形链表问题(判环、求入口点)
- 浅谈Endpoint
- 3.MySQL插入数据, 读取数据、Where子句和Order By关键字
- VOC格式标签转YOLO格式
- Four departments including the Ministry of Industry and Information Technology promote green smart home products to the countryside
- String类创建的对象在JVM中的内存分配和equals与==的区别
- 工信部等四部门推动绿色智能家居产品下乡
- PyTorch中 torch.nn与torch.nn.functional的区别
猜你喜欢
SiamFC:用于目标跟踪的全卷积孪生网络 fully-convolutional siamese networks for object tracking
3D精彩案例,清软英泰建成综合轻量化显示平台!
[STL]vector
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Exchange、HOOPS Communicator
C语言:调整奇数偶数顺序
静态路由的原理与配置
【Rust指南】快速入门|开发环境|hello world
世界顶尖3D Web端渲染引擎:HOOPS Communicator技术介绍(一)
SSM integration development case
VRRP原理及配置
随机推荐
种子数据报错:liquibase.exception.ValidationFailedException: Validation Failed
RestFul,会话技术,Fiddler
C#基础学习
火星人 --简单的数学题
ncnn 推理猫狗识别
pytorch指定GPU
Four departments including the Ministry of Industry and Information Technology promote green smart home products to the countryside
Unity 3D模型展示框架篇之资源打包、加载、热更(二)
PyTorch中 torch.nn与torch.nn.functional的区别
9.进程和计划任务管理(1)
权限(上)
[STL]vector
4.MySQL更新和删除数据
教你更好的使用 idea 2021.2.3
pip3换源提升速度
(四)BP神经网络预测(上)
浅谈Endpoint
LVM与磁盘配额
Result consisted of more than one row
resourcemanager启动失败,别的节点成功