Custom trailing_slash

If a string is passed into the SimpleRouter, append that to the regex determining the route. This will prevent unnecessary confusion when a PATCH/PUT request is made to a given endpoint and a slash is omitted. Have lost a bit of dev time figuring out where the `request.data` has gone because the endpoint was right, but the slash was missing.

With this change, one can use  `SimpleRouter(trailing_slash='/?')` to direct to any of the given endpoints, while not losing any of the prior functionality.
This commit is contained in:
Jamie Weatherby 2017-05-18 16:37:17 -04:00 committed by GitHub
parent 1e9e1a5bfe
commit ed3fc4a3d1

View File

@ -126,7 +126,10 @@ class SimpleRouter(BaseRouter):
]
def __init__(self, trailing_slash=True):
self.trailing_slash = trailing_slash and '/' or ''
if isinstance(trailing_slash, str):
self.trailing_slash = trailing_slash
else:
self.trailing_slash = trailing_slash and '/' or ''
super(SimpleRouter, self).__init__()
def get_default_base_name(self, viewset):