01 flask-script模块简单使用介绍
2020-06-25 21:47
127 查看
flask-script
Flask每次启动只能在脚本中作为参数传给app.run()函数,比如我要启动端口为8000,那就需要在代码中或者配置文件中修改,很不方便。
Flask-Scrip就是这么一个Flask扩展,为Flask程序添加一个命令行解析器,可以使用命令行进行启动参数传递。
- 安装
pip install flask-script
- 继承flask-script到flask应用中
保存下面代码为manager.py
from flask import Flask from flask_script import Manager app = Flask(__name__) manager = Manager(app=app) @app.route('/') def index(): return 'Hello, world~!' if __name__ == '__main__': manager.run()
- 自定义启动方式
cmd命令行下查看启动命令帮助
在cmd命令行中,进入manager.py所在的路径,执行如下命令查看帮助(或者进入对应目录,在对应路径中输入cmd,即可打开当前路径的命令行模式…)
python manager.py runserver --help -?, --help show this help message and exit -h HOST, --host HOST -p PORT, --port PORT --threaded --processes PROCESSES --passthrough-errors -d, --debug enable the Werkzeug debugger (DO NOT use in production code) -D, --no-debug disable the Werkzeug debugger -r, --reload monitor Python files for changes (not 100% safe for production use) -R, --no-reload do not monitor Python files for changes --ssl-crt SSL_CRT Path to ssl certificate --ssl-key SSL_KEY Path to ssl key
C:\Users\Admin\Desktop\markdown>python manager.py runserver -h 0.0.0.0 -p 8000 -d -r * Serving Flask app "manager" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: on * Restarting with stat * Debugger is active! * Debugger PIN: 137-965-202 * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
相关文章推荐
- 【scikit-learn】01:使用案例对sklearn库进行简单介绍
- python中loggin模块的简单功能介绍及使用
- joi模块验证的介绍与使用——一种基于schema的nodejs的对象校验,简单易用
- 第十二章:flask_script 的介绍和安装与使用
- 学习笔记(01):Python可以这样学(第一季:Python内功修炼)-版本介绍、安装与简单使用...
- Python-爬虫1-爬虫介绍及简单使用、urllib模块的介绍及使用
- 学习笔记(01):Python可以这样学(第一季:Python内功修炼)-版本介绍、安装与简单使用...
- spring框架使用的设计模式,及包含模块的简单介绍
- 使用react-native做一个简单的应用-01项目介绍
- logging模块的简单使用以及tornado中的log简单介绍
- node.js中debug模块的简单介绍与使用
- Flask之flask-script模块使用
- app常见功能模块及其使用简单介绍
- Python全栈(七)Flask框架之10.ORM插件、Script、Migrate和WTF的简单使用
- Jetty系列: 01- 基本使用和简单介绍
- 简单介绍python-nmap 模块的使用
- joi模块验证的介绍与使用——一种基于schema的nodejs的对象校验,简单易用
- 宏模块的简单使用
- Gravatar 全球通用头像简单介绍与使用教程