2

我需要通过url中的最后一个参数将包含斜杠的字符串传递给我的bottlepy服务器,但由于斜杠被视为参数分隔符,服务器不会按照我需要的方式处理它。我找到了一个关于烧瓶如何支持这一点的页面:http: //flask.pocoo.org/snippets/76/ 但是还没有在瓶中找到类似的解决方案

4

1 回答 1

2

听起来像你想要的:path

:path 以非贪婪的方式匹配包括斜线字符在内的所有字符,并且可用于匹配多个路径段。

例如,

@route('/root/<path:thepath>')
def callback(thepath):
    # `thepath` is everything after "/root/" in the URI.
    ...

编辑:响应 OP 的评论(如下),这里有一个对我有用的片段:

from bottle import Bottle, route

app = Bottle()

@app.route('/add/<uid>/<collection>/<group>/<items:path>')
def add(uid, collection, group, items):
    return 'your uri path args: {}, {}, {}, {}\n'.format(uid, collection, group, items)

app.run(host='0.0.0.0', port=8081)

产量:

% ~>curl 'http://127.0.0.1:8081/add/1/2/3/and/now/a/path'
your uri path args: 1, 2, 3, and/now/a/path
于 2013-11-04T12:45:44.280 回答