From ed3fc4a3d1869d408c937f979bac0f68161637d5 Mon Sep 17 00:00:00 2001 From: Jamie Weatherby Date: Thu, 18 May 2017 16:37:17 -0400 Subject: [PATCH 1/2] 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): From 87bfe0410ec4c9257d148e7dc7bfc7f2885cefdc Mon Sep 17 00:00:00 2001 From: Jamie Weatherby Date: Thu, 18 May 2017 17:27:53 -0400 Subject: [PATCH 2/2] Flake8 remove trailing white space --- rest_framework/routers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/routers.py b/rest_framework/routers.py index 03d99c0f9..782a01671 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -128,7 +128,7 @@ class SimpleRouter(BaseRouter): def __init__(self, trailing_slash=True): if isinstance(trailing_slash, str): self.trailing_slash = trailing_slash - else: + else: self.trailing_slash = trailing_slash and '/' or '' super(SimpleRouter, self).__init__()