libb.make_url
- make_url(path, **params)[source]
Generate URL with query parameters.
Inspired by
werkzeug.urls.Href. Assumes traditional multiple params (does not overwrite). Use__replace__to overwrite params. Use__ignore__to filter out certain params.- Parameters:
path (str) – Base URL path.
params – Query parameters.
- Returns:
Complete URL with query string.
- Return type:
Example:
>>> ignore_fn = lambda x: x.startswith('_') >>> kw = dict(fuz=1, biz="boo") >>> make_url('/foo/', _format='excel', __ignore__=ignore_fn, **kw) '/foo/?fuz=1&biz=boo' >>> make_url('/foo/?bar=1', _format='excel', **kw) '/foo/?_format=excel&fuz=1&biz=boo&bar=1' >>> make_url('/foo/', bar=1, baz=2) '/foo/?bar=1&baz=2' >>> make_url('/foo/', **{'bar':1, 'fuz':(1,2,), 'biz':"boo"}) '/foo/?bar=1&fuz=1&fuz=2&biz=boo' >>> make_url('/foo/?a=1&a=2') '/foo/?a=1&a=2' >>> kwargs = dict(fuz=1, biz="boo", __ignore__=ignore_fn) >>> xx = make_url('www.foobar.com/foo/', **kwargs) >>> 'www' in xx and 'foobar' in xx and '/foo/' in xx and 'fuz=1' in xx and 'biz=boo' in xx True >>> xx = make_url('/foo/', _format='excel', **kwargs) >>> '_format=excel' in xx False >>> 'fuz=1' in xx True >>> 'biz=boo' in xx True >>> yy = make_url('/foo/?bar=1', _format='excel', **kwargs) >>> 'bar=1' in yy True >>> '_format=excel' in yy False >>> zz = make_url('/foo/', **{'bar':1, 'fuz':(1,2,), 'biz':"boo"}) >>> 'fuz=1' in zz True >>> 'fuz=2' in zz True >>> qq = make_url('/foo/?a=1&a=2') >>> 'a=1' in qq True >>> 'a=2' in qq True