flask的多个url对应同一个视图函数
# -*- coding: utf-8 -*- from flask import Flask app = Flask(__name__) @app.route('/') def index(): return "hello flask" @app.route('/post_only', methods=["POST", "GET"]) def post_only(): return "post only page" @app.route("/hello", methods=["POST"]) def hello(): return "hello 1" @app.route("/hello", methods=["GET"]) def hello2(): return "hello 2" @app.route("/hi1") @app.route("/hi2") def hi(): return "hi page" if __name__ == '__main__': # 通过url_map可以查看整个flask中的路由信息 print(app.url_map) # 启动flask程序 app.run(debug=True)
输出:
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

更多精彩