作用:url_for获取蓝图里面函数的动态路径 用法:
注意:该url_for会得到你调用函数的路径,后面跟不跟参数根据你调用的函数是不是有参数,如果没有你传入参数之后变成值的形式。比如:http://106.12.109.69:8000/path/2?a=3;变成?变量=值的形式 后端的写法 redirect(res):重定向url_for得到的函数的路径 举例: 第一种不需要参数的函数: @blue.route("/index/") def index(): return "我是index" @blue.route("/check/") def check_url(): res = url_for("first.index") print(res)return redirect(res) 第二种需要参数的函数 @blue.route("/path/<int:id>") def path(id): return "你的参数是%d" %id @blue.route("/check/") def check_url(): res = url_for("first.path",id=2) print(res) return redirect(res) |
|
来自: 郭祺迦 > 《url_for静态资源加载和反向解析》