查看flask中所有的路由信息(同时查看/设置允许的请求方式get、post)

查看flask中所有的路由信息(同时查看/设置允许的请求方式get、post)

# -*- coding: utf-8 -*-
from  flask import Flask

app = Flask(__name__)


@app.route('/')
def index():
    return "hello flask"

@app.route('/post_only',methods=["POST"])
def post_only():
    return "post only page"


if __name__ == '__main__':
    # 通过url_map可以查看整个flask中的路由信息
    print(app.url_map)
    # 启动flask程序
    app.run(debug=True)

输出:

 

如果要允许get方式访问post_only则,

@app.route('/post_only',methods=["POST","GET"])
def post_only():
    return "post only page"

输出:

猜你喜欢

转载自www.cnblogs.com/andy9468/p/10871403.html
今日推荐