主题
入门
第一个web服务
查看代码:https://gitee.com/PatrickW/flask-web/blob/master/src/1hellowold.py
python
from flask import Flask
app = Flask(__name__)
SERVER_PORT=9999
@app.route('/')
def index():
return '<h1>Hello Flask!</h1>'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=SERVER_PORT, debug=True)
另一种启动项目
shell
export FLASK_APP=1hellowold.py # 指定启动项目
export FLASK_DEBUG=1 # 启动调试模式
flask run --host=0.0.0.0 --port=9999 # 启动项目
shell
(base) ➜ flask run --host=0.0.0.0 --port=9999
* Serving Flask app '1hellowold.py'
* Debug mode: off
WARNING: This is a development server.
Do not use it in a production deployment.
Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:9999
* Running on http://192.168.1.4:9999
Press CTRL+C to quit