From ed3fc4a3d1869d408c937f979bac0f68161637d5 Mon Sep 17 00:00:00 2001 From: Jamie Weatherby Date: Thu, 18 May 2017 16:37:17 -0400 Subject: [PATCH] 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. --- rest_framework/routers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rest_framework/routers.py b/rest_framework/routers.py index fce968aa0..03d99c0f9 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -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):