mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow passing None to url_for() to get the url_prefix
This commit is contained in:
parent
c502d64c0e
commit
65c6d6d86c
@ -290,5 +290,7 @@ class Router(object):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def url_for(self, route, **kwargs):
|
def url_for(self, route, **kwargs):
|
||||||
|
if route is None:
|
||||||
|
return self.url_prefix or '/'
|
||||||
route = getattr(route, 'route_key', route)
|
route = getattr(route, 'route_key', route)
|
||||||
return self.url_prefix + self.routes[route].url_for(**kwargs)
|
return self.url_prefix + self.routes[route].url_for(**kwargs)
|
||||||
|
@ -97,3 +97,4 @@ class TestRouter(BaseTest):
|
|||||||
self.ae(ep, soak_opt), self.ae(args, ['a/b'])
|
self.ae(ep, soak_opt), self.ae(args, ['a/b'])
|
||||||
|
|
||||||
self.ae(router.url_for('/needs quoting', x='a/b c'), '/needs quoting/a%2Fb%20c')
|
self.ae(router.url_for('/needs quoting', x='a/b c'), '/needs quoting/a%2Fb%20c')
|
||||||
|
self.ae(router.url_for(None), '/')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user