Flask - Flask扩展,Flask-Script
一.Flask-Script
Flask-Script是一个Flask扩展,为Flask程序添加了一个命令行解析器。Flask-Script自带了一组常用选项,而且还支持自定义命令
pip3 install flask-script
from flask_script import Manager .... manager = Manager(app) # 这里服务器有manager启动,启动后就能解析命令行了 if __name__ == '__main__': manager.run()
(venv) zhangjindeMacBook-Pro:blueprint zhangjin$ python s1.py usage: s1.py [-?] {shell,runserver} ... positional arguments: {shell,runserver} shell Runs a Python shell inside Flask application context. runserver Runs the Flask development server i.e. app.run() optional arguments: -?, --help show this help message and exit (venv) zhangjindeMacBook-Pro:blueprint zhangjin$
shell命令用于在程序的上下文启动Python Shell会话,可以使用这个会话运行任务或测试,还可以调试异常。
runserver就是来启动Web服务器了,
(venv) zhangjindeMacBook-Pro:blueprint zhangjin$ python s1.py runserver -h usage: s1.py runserver [-?] [-h HOST] [-p PORT] [--threaded] [--processes PROCESSES] [--passthrough-errors] [-d] [-D] [-r] [-R] [--ssl-crt SSL_CRT] [--ssl-key SSL_KEY] s1.py runserver: error: argument -h/--host: expected one argument (venv) zhangjindeMacBook-Pro:blueprint zhangjin$
(venv) zhangjindeMacBook-Pro:blueprint zhangjin$ python s1.py runserver -h 0.0.0.0 -p 8000 * Serving Flask app "s1" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: off * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
浙公网安备 33010602011771号