当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
yolov5 detects the number of labels in the dataset
C语言:调整奇数偶数顺序
74HC595 chip pin description
.net(三) 项目结构
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Exchange、HOOPS Communicator
P1064 金明的预算方案
我这是来宣传一下
Shell之函数与数组
VLAN与静态VLAN的配置
贪吃蛇小游戏——C语言
Shell编程之正则表达式
One-click login server script
App测试
SSM整合开发案例
【机器学习】降维代码练习
监视文本框的输入
浅谈Flask_script
SOLIDWORKS 2022新功能直播揭秘!速来围观!
web基本概念
js数组相关知识复习