2013-11-04 32 views
1

我需要将包含斜线的字符串通过URL中的最后一个参数传递给我的瓶装服务器,但由于斜杠会像参数分隔符那样处理,服务器无法按需要处理它。 我发现了一个网页约烧瓶如何支持这一点: http://flask.pocoo.org/snippets/76/ 但没有找到一瓶类似的解决方案还将包含斜线的参数传递给瓶子

+0

发现: @route( '/组/ ') 从: http://stackoverflow.com/questions/8171618/how-do-you-accept-any-url-in-a-python-bottle-server –

+0

With Bottle 0.11你应该比're'更喜欢'path' ......但是无论flo在你的船上。 :) –

回答

1

听起来像是你想:path

:path matches all characters including the slash character in a non-greedy way and may be used to match more than one path segment.

例如,

@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 
+0

那么,这是在我给出的链接中描述的烧瓶解决方案,但在瓶中,它给了我这个错误: 回溯(最近呼叫最后): 文件“myfile.py”,行105,在 。 .. 文件“/Library/Python/2.7/site-packages/bottle-0.11.6-py2.7.egg/bottle.py”,第328行,加 mask,in_filter,out_filter = self.filters [mode ](conf) KeyError:'items' [以0.1s结束,退出代码1] –

+0

好的。我需要查看您的代码以进一步帮助您。你如何定义路线? –

+0

'@route( '/添加/ ///') 高清加(UID,收集,组,项目):' –