Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing arguments containing slashes to bottle

Tags:

python

bottle

I need to pass strings containing slashes through the last argument in a url to my bottlepy server but since slashes get treated like argument separators the server doesn't handle it the way I need to. I found a page about how flask supports this: http://flask.pocoo.org/snippets/76/ But haven't found a similar solution in bottle yet

like image 835
Jurriaan Roelofs Avatar asked Dec 20 '25 20:12

Jurriaan Roelofs


1 Answers

Sounds like you want :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.

For example,

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

EDIT: In response to OP's comment (below), here's a snippet which works for me:

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)

Yields:

% ~>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
like image 130
ron rothman Avatar answered Dec 22 '25 09:12

ron rothman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!