采用python flask 开发如何管理 host port

1、#pip install flask_script 安装flask_script包   

Flask-Script 是一个 Flask 扩展,为 Flask 程序添加了一个命令行解析器。Flask-Script 自带 了一组常用选项,而且还支持自定义命令。 

2、在源代码中 import Manager  ,代码如下:


from flask import Flask
from flask.ext.script import Manager

app = Flask(__name__)

manager = Manager(app)

@app.route('/')
def index():
    return '<h1>Hello World!</h1>'
@app.route('/user/<name>')
def user(name):
    return '<h1>Hello, %s!</h1>' % name
if __name__ == '__main__':
    manager.run()

保存为 hello.py

3、执行 python hello.py  runserver -?,结果如下

usage: flask02c.py runserver [-?] [-h HOST] [-p PORT] [--threaded]

                             [--processes PROCESSES] [--passthrough-errors]

                             [-d] [-D] [-r] [-R]


Runs the Flask development server i.e. app.run()


optional arguments:

  -?, --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{'const':

                        True, 'help': 'monitor Python files for changes (not

                        100% safe for production use)', 'option_strings':

                        ['-r', '--reload'], 'dest': 'use_reloader',

                        'required': False, 'nargs': 0, 'choices': None,

                        'default': None, 'prog': 'flask02c.py runserver',

                        'container': <argparse._ArgumentGroup object at

                        0x10fe85190>, 'type': None, 'metavar': None}afe for

                        production use)

  -R, --no-reload       do not monitor Python files for changes

就可以进行相关主机与端口的指定。





你可能感兴趣的:(python,manager,pip,flask,flask_script)