rules = app.url_map.iter_rules()
[rule.rule for rule in rules] # 路由
[rule.endpoint for rule in rules] # 视图
rules
就是整个Web
项目的路由表
# -*- coding: utf-8 -*-
# @File : 05路由列表.py
# @author: 北极的三哈
# @email : Flymeawei@163.com
# @Time : 2022/12/3 18:47
""""""
import json
from flask import Flask
app = Flask(__name__, static_url_path='/Flyme', static_folder='static')
@app.route('/rules')
def rules_func():
# rules就是整个Web项目的路由表
rules = app.url_map.iter_rules()
for rule in rules:
print(f'视图函数:{rule.endpoint}, 路由:{rule.rule}')
return json.dumps({rule.endpoint: rule.rule for rule in rules})
@app.route('/test')
def test():
return ''
@app.route('/test2')
def test2():
return ''
if __name__ == 'main':
app.run(host='0.0.0.0', port=8080, debug=True)
最后
以上就是爱撒娇鸭子最近收集整理的关于【Flask框架】——04 路由列表信息的全部内容,更多相关【Flask框架】——04内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复