zoukankan      html  css  js  c++  java
  • 同一个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")
    def hello():
        return "hello 1"
    
    @app.route("/hello")
    def hello2():
        return "hello 2"
    
    
    if __name__ == '__main__':
        # 通过url_map可以查看整个flask中的路由信息
        print(app.url_map)
        # 启动flask程序
        app.run(debug=True)

    输出:

    ====================================================

    同一个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"
    
    
    if __name__ == '__main__':
        # 通过url_map可以查看整个flask中的路由信息
        print(app.url_map)
        # 启动flask程序
        app.run(debug=True)
    

    输出:

  • 相关阅读:
    还需要做恰当的解读,此时你可能需要一些书:
    创业公司的架构演进史
    任务调度平台Cuckoo-Schedule
    ORACLE中死锁
    Action的模型绑定
    三次握手、四次握手、backlog
    Django框架
    扩展BootstrapTable的treegrid功能
    Identity Service
    Linux权限
  • 原文地址:https://www.cnblogs.com/andy9468/p/10871453.html
Copyright © 2011-2022 走看看