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

一、#pip install flask_script 安装flask_script包   python

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

二、在源代码中 import Manager  ,代码以下:app


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.pyui

三、执行 python hello.py  runserver -?,结果以下this

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

                             [--processes PROCESSES] [--passthrough-errors]命令行

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


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


optional arguments:server

  -?, --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

就能够进行相关主机与端口的指定。

相关文章
相关标签/搜索