- Web本质
from werkzeug.wrappers import Request, Response from werkzeug.serving import run_simple @Request.application def hello(request): return Response(‘Hello World!‘) if __name__ == ‘__main__‘: run_simple(‘localhost‘, 4000, hello)
- 快速入门
from flask import Flask # 实例化Flask对象 app = Flask(__name__) # 生成路由关系,并把关系保存到某个地方,app对象的 url_map字段中 @app.route(‘/xxxx‘) # @decorator # 带参数装饰器. def index(): return "Index" # def index(): # return "Index" # app.add_url_rule(‘/xxx‘, "n1", index) # 添加路由关系的第二种方式 if __name__ == ‘__main__‘: # 启动程序,监听用户请求 # 一旦请求到来,执行 app.__call__方法 # 封装用户请求 # 进行路由匹配 app.run()