主题
TemplateRoute
将一个具体的路由字符串与带参数的路由模板进行匹配。
实例会把原始路由保存在 route 中,并在成功调用 match() 后,将匹配到的模板参数作为动态属性暴露出来。每次新的匹配尝试前,上一次匹配捕获的参数属性都会被重置为 None,以避免陈旧的值在不同检查之间泄漏。
方法
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
match | bool | — | Tries to match this instance route against a route template. The template is compiled with repath.pattern(). If matching succeeds, named parameters are stored and also assigned as attributes on this object (for example, self.user_id). If matching fails, previously captured attributes remain cleared. Args: route_template: Route template in a format supported by repath.pattern(). Returns: True if the route matches the template; otherwise False. |