当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Anaconda 使用代理
定时任务组件Quartz
db2数据库备份恢复问题
Redis(八)集群
.net(四) 数据层实现
Native JDBC operation database
Kotlin Coroutines - Exception Handling
安全的Md5加密:两次加密(加盐)
JS基础1
梅科尔工作室--BP神经网络培训笔记
接口测试概念
Redis(七) 主从复制(二)哨兵模式
(四)BP神经网络预测(上)
.net(二) 配置数据库
Decimal工具类
实现弹簧柔性状态的2种方式 | Solidworks教程
RestFul,会话技术,Fiddler
LeetCode:876. 链表的中间结点————简单
图像处理(一)图像基础
Collection 接口 & List 接口









