-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding optional trailing_slash for SimpleRouter and test #9659
Conversation
Clarified the identifiers for the rate period as per discussion https://github.com/encode/django-rest-framework/discussions/9639
…es-docs Update throttling.md as per discussion https://github.com/encode/django-rest-framework/discussions/9639
This does not break the previous behaviour, where trailing_slash can be only True or False. By default it stays True. It adds an extra option: when trailing_slash=None (or any other value), the trailing_slash becomes optional.
This is alternative to use a custom class like:
in our code. |
For clarity, especially in documentation, one may also use: |
Why having an optional trailing slash (in the regex) and not using the |
Hi @sevdog and thank you for replying. I have an embedded device that sends a POST request to
So losing the data is the first concern. Secondly, it is more efficient than having Django constantly performing internal redirects (apart for losing data). The difference in the regex evaluation runtime should be negligible. See also https://stackoverflow.com/a/46163870/3396785 Any thoughts? |
An other concern is that with this kind of implementation if you have You could also achieve the same result by using two routers: one with |
An other way to obtain this is to override CommonMiddleware to provide a redirection using HTTP status 308 which tells the client to keep method and body. |
I did not consider the
Using two routers does not seem DRY. Not sure about the middleware solution. I think that's more of a Django PR than of this framework. How would you address this optional trailing slash thing in one of your projects? |
This seems to be an issue with the embedded device to me, because See also https://stackoverflow.com/q/61547014 This said, this PR is not going to be merged because of current contributing policy because there are ways to make everything work without any change in DRF and this is not a feature of Django. |
Description
For someone it is annoying to have to choose specifically if an API has to have or not the trailing slash. So I added a way to have an optional trailing slash.
This does not break the previous behaviour, where trailing_slash can be only
True
orFalse
. By default it staysTrue
as before.There is not an extra option: when
trailing_slash=None
(or any other value), thetrailing_slash
becomes optional.For clarity, we may use something else than
None
.Test has been added.