flask的多个url对应同一个视图函数

时间:2019-05-15 19:41:09   收藏:0   阅读:258

 技术分享图片

# -*- 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)

输出:

技术分享图片

技术分享图片

 

原文:https://www.cnblogs.com/andy9468/p/10871491.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!