mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
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:
parent
1e9e1a5bfe
commit
ed3fc4a3d1
|
@ -126,7 +126,10 @@ class SimpleRouter(BaseRouter):
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, trailing_slash=True):
|
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__()
|
super(SimpleRouter, self).__init__()
|
||||||
|
|
||||||
def get_default_base_name(self, viewset):
|
def get_default_base_name(self, viewset):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user