如何从flask中的.route获取url?

gijlo24d  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(303)

我有一个flask应用程序,它根据在@.route()中传递的对象将用户路由到报告页面:

@mod.route('/page/<object>')
def page(object):
   #some manipulations based on object
   return redirect(url_for("another_page.index"))

它适用于域名、电子邮件或任何其他类型的对象,但如果对象是url,则无法使用404,基本上是以“http://”开头。
问题:在这种情况下,我如何传递url?

eyh26e7m

eyh26e7m1#

找到了一个简单的解决方案。我所要做的就是为一个对象添加一个转换器“路径”:

@mod.route('/page/<path:object>')
def page(object):
  #some manipulations based on object
  return redirect(url_for("another_page.index"))

flask 路线文件

相关问题