一、添加url方式
- @app.route(‘xxx’)
- app.add_url_rule(‘xxx’, view_func=demo)
二、原理
- url和视图函数通过endpoint关联起来。url<---->endpoint<---->view_func;
- url和endpoint的对应关系存入到url_map中;
- 以endpoint为key,view_function为值存入view_functions字典中。
- 添加url的两种方法都可以指定endpoint,如果endpoint未指定,会把视图函数的名称做为默认的endpoint的值。
Flask路由原理
原文:https://www.cnblogs.com/blueandsky/p/11628537.html