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 に答える