Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Check for empty router prefix; adjust URL accordingly
It's easiest to fix this issue after we have made the regex.  To try
to fix it before would require doing something different for List vs
Detail, which means we'd have to know which type of url we're
constructing before acting accordingly.
  • Loading branch information
c17r committed Sep 15, 2016
commit a372a8edea70260ebfb559f3d0bd692132cdfb40
8 changes: 8 additions & 0 deletions rest_framework/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def urls(self):


class SimpleRouter(BaseRouter):

routes = [
# List route.
Route(
Expand Down Expand Up @@ -258,6 +259,13 @@ def get_urls(self):
trailing_slash=self.trailing_slash
)

# If there is no prefix, the first part of the url is probably
# controlled by project's urls.py and the router is in an app,
# so a slash in the beginning will (A) cause Django to give
# warnings and (B) generate URLS that will require using '//'.
if not prefix and regex[:2] == '^/':
regex = '^' + regex[2:]

view = viewset.as_view(mapping, **route.initkwargs)
name = route.name.format(basename=basename)
ret.append(url(regex, view, name=name))
Expand Down