秦悦明的运维笔记

[flask] hello

0.hello.py

1
2
3
4
5
6
7
8
9
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return '<h1>hello world.</h1>'
if __name__ == '__main__':
app.run(debug=True)

运行起来就是python hello1.py

1
2
3
4
5
python hello1.py !10032
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger pin code: 270-940-657

1.增加一个manager

类似django的运行方式。需要的步骤也很少。
需要引入一个ext.script的包.

1
2
3
4
5
from flask.ext.script import Manager
manager = Manager(app)
# ...
if __name__ == '__main__':
manager.run()