您如何在Python Bottle服务器中接受任何URL? [英] How do you accept any URL in a Python Bottle server?

查看:104
本文介绍了您如何在Python Bottle服务器中接受任何URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用瓶子Sehttp://bottlepy.org/docs/dev/routing.html#wildcard-filters

Using a Bottle Sehttp://bottlepy.org/docs/dev/routing.html#wildcard-filters

我想接受任何网址,然后对网址进行处理.

I'd like to accept any url, and then do something with the url.

例如

@bottle.route("/<url:path>")
def index(url):
  return "Your url is " + url

这很棘手,因为URL中包含斜杠,而Bottle用斜杠分隔.

This is tricky because URLs have slashes in them, and Bottle splits by slashes.

推荐答案

基于新的Bottle(v0.10),使用重新过滤器:

Based on new Bottle (v0.10), use a re filter:

@bottle.route("/<url:re:.+>")

您也可以使用旧参数来做到这一点:

You can do that with old parameters too:

@bottle.route("/:url#.+#")

这篇关于您如何在Python Bottle服务器中接受任何URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆