Guide to URLs
There are many built-in utilities in Commonplace for constructing and interpreting URLs.
urls.reverse(view_name[, arguments])
The reverse()
method allows you to generate an absolute URL to a view within your project. The first parameter should be the view name (as defined by the view_name
field in the routes.js
file). If the route accepts arguments, they should be passed to the arguments
parameter. arguments
must be a list of strings, if specified.
This method will always return a string.
urls.api.url(api_route[, arguments[, parameters]])
The api.url()
method generates a URL based on API routes. api_route
is the name of the route (as defined in routes_api.js
; see the guide to API routes for more). arguments
is a list of strings which will be format
ed into the URL. parameters
may also be specified, which adds URL parameters to the resulting URL. Note: parameters
will be overridden by default API parameters (such as lang
, region
, etc.).
utils.urlparams(urls.api.url('route', ['foo']), {abc: 'def'});
// equivalent to
urls.api.url('route', ['foo'], {abc: 'def'});
urls.api.params(api_route, parameters)
Shorthand for urls.api.url(api_route, [], parameters)
.
urls.api.sign(url)
This method will add the default API parameters to url
.
This is a namespace that provides methods that do not add default API parameters. This is the same as the urls.api.*
variants, sans the call to urls.api.sign
.
urls.api.unsigned.url(api_route[, arguments[, parameters]])
urls.api.unsigned.params(api_route, parameters)
urls.media(path)
This method returns a URL to a media resource. The path that media files can be found should be specified in settings.media_url
. This will automatically figure out whether to append or prepend slashes.