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)

輸出:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM