首先:flask是一个基于Werkzeug,Jinja2的一个python的微服务框架。 安装flask框架: pip install flask 一个最小的最简单的flask应用: from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return "Hello World!" if __name__ == "__main__": app.run() 我们把这段程序名保存为任意一个名字,如test.py,然后使用解释器来运行它, python test.py,然后我们就可以通过http://127.0.0.1:5000/来访问他。 注意,程序的名字一定不能保存为flask.py,否则会与Flask框架本身冲突。 注意:这个程序现状只能在本机访问,如果是想要在其他地方全部访问,那么 需要将代码改为: app.run(host='0.0.0.0') 这会让系统监听所有的公网IP。 flask简单调试模式: 我们可以给app实例添加一个debug参数: app.debug = True app.run() 或者是: app.run(debug=True) 两种效果完全相同。