当前位置:网站首页>Flask (II) - route

Flask (II) - route

2022-06-11 09:26:00 zju_ cbw

modern Web The framework uses routing technology to help users remember applications URL. Direct access to the desired page without navigating from the home page .

Flask Medium route() A decorator is used to decorate URL Bind to function . for example

from flask import Flask

app = Flask(__name__)


@app.route('/hello')
def hello_world():
    return 'Hello World!!!'


if __name__ == '__main__':
    app.run(debug = True)

here ,URL /hello Rules are bound to hello_world() function . therefore , If the user accesses URL : http://localhost:5000/hello , Will call hello_world() function , The result output of the execution in this function will be presented in the browser .

Application object add_url_rule() Function can also be used to URL Bind to function , As shown in the example above , Use route().

def hello_world():
     return 'hello world'
app.add_url_rule('/hello', 'hello', hello_world)
原网站

版权声明
本文为[zju_ cbw]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203012301369751.html