Monday, October 21, 2019

Re: Bug or Feature: Trailing Slash appended to two places in a URL

I want the url to be /api/v1/case. I have no problem building that URL, it's just that due to a config error on my behalf that I discovered this unusual behaviour.

Two things strike me as particular strange. The first thing is the difference between how the URL is rendered depending on whether APPEND_SLASH is True or False, and the second is where does the space come from in the rendered URL when APPEND_SLASH is False.

Anyway, to make a long story short I have submitted a bug report. I'll update this thread when I get an answer.

Cheers,

Conor

On Monday, October 21, 2019 at 5:13:11 PM UTC+2, lemme smash wrote:
i'm not sure, but i can say that it's quite strange not to have trailing slash on `include` path. you want to have something like `api/v1case`?

On Sunday, October 20, 2019 at 1:07:48 AM UTC+3, Conor wrote:
Hi All,

I'm not sure whether this is a feature or a bug, so I thought it best to air it here before filing a bug report.

In short I have a URL which will be '/api/v1/case/' if APPEND_SLASH false True, or '/api/v1 case' if APPEND_SLASH = False.

To reproduce this, I have a project urls.py file with the following

 path('api/v1', include('api.urls')) - (note there is no trailing slash)

And an api/urls.py with the following

path('case', CasesView.as_view(), name='all-cases'),

What I assume is happening is that my complete URL is made up of two URLs, namely the first URL from the project urls.py file and the second URL from api/urls.py, and that the method that append's a slash to URLs is appending a slash to both of them. If you have APPEND_SLASH to True, then the URL is accessible via '/api/v1/case/' or '/api/v1/case', but if it APPEND_SLASH is False, then the URL becomes '/api/v1 case'

The thing that makes me think that perhaps this isn't a bug, is that I seemingly just didn't configure Django properly. It could be as simple as that.

However, the reason I think this is a bug, is that the behaviour, at least to me is non-obvious. That's not to say when you stop and think about it that it isn't perhaps logical, if indeed there are two URLs which have slashes appended to them in order to make the final URL, but on first glance when I read about Django's APPEND_SLASH feature, I think of the final URL, the one that the user will see, not of two separate URLs  that are being put together to make the final product.

Please let me know your thoughts and if you think it is a bug or not.

Cheers,

Conor

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0dd771ae-3ced-4c78-a5d2-ce727e554635%40googlegroups.com.

No comments:

Post a Comment