MCPcopy Index your code
hub / github.com/encode/django-rest-framework / get_urls

Method get_urls

rest_framework/routers.py:266–311  ·  view source on GitHub ↗

Use the registered viewsets to generate a list of URL patterns.

(self)

Source from the content-addressed store, hash-verified

264 )
265
266 def get_urls(self):
267 """
268 Use the registered viewsets to generate a list of URL patterns.
269 """
270 ret = []
271
272 for prefix, viewset, basename in self.registry:
273 lookup = self.get_lookup_regex(viewset)
274 routes = self.get_routes(viewset)
275
276 for route in routes:
277
278 # Only actions which actually exist on the viewset will be bound
279 mapping = self.get_method_map(viewset, route.mapping)
280 if not mapping:
281 continue
282
283 # Build the url pattern
284 regex = route.url.format(
285 prefix=prefix,
286 lookup=lookup,
287 trailing_slash=self.trailing_slash
288 )
289
290 # If there is no prefix, the first part of the url is probably
291 # controlled by project's urls.py and the router is in an app,
292 # so a slash in the beginning will (A) cause Django to give
293 # warnings and (B) generate URLS that will require using '//'.
294 if not prefix:
295 if self._url_conf is path:
296 if regex[0] == '/':
297 regex = regex[1:]
298 elif regex[:2] == '^/':
299 regex = '^' + regex[2:]
300
301 initkwargs = route.initkwargs.copy()
302 initkwargs.update({
303 'basename': basename,
304 'detail': route.detail,
305 })
306
307 view = viewset.as_view(mapping, **initkwargs)
308 name = route.name.format(basename=basename)
309 ret.append(self._url_conf(regex, view, name=name))
310
311 return ret
312
313
314class APIRootView(views.APIView):

Callers

nothing calls this directly

Calls 6

get_lookup_regexMethod · 0.95
get_routesMethod · 0.95
get_method_mapMethod · 0.95
copyMethod · 0.80
updateMethod · 0.45
as_viewMethod · 0.45

Tested by

no test coverage detected