#30895: Multiples trailing slashes appended to URL
---------------------------------+--------------------------------------
     Reporter:  conorcunningham  |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  Core (URLs)      |                  Version:  2.2
     Severity:  Normal           |               Resolution:
     Keywords:  urls, url        |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------
Description changed by conorcunningham:

Old description:

> I'm not sure whether this is a feature or a bug, but failing in my
> attempt to get an answer in #django or django-users, I thought it best to
> report it.
> I have come
>
> === Summary
> In short I have a URL which will be either ```/api/v1/case/``` if
> ```APPEND_SLASH=True,``` or ```/api/v1 case``` if ```APPEND_SLASH =
> False```.
> The URL ```/api/v1/case/``` is made up of two URLS, namely ```/api/v1```
> and ```/case```, one from the projects ```urls.py``` and the other from
> the app's ```urls.py```. What I suspect is happening is that a trailing
> slash is being appended to both the URLS before they are concatenated to
> make the final URL.
>
> **Django Version**: 2.2.6
> **Installed Apps**:
> django-allauth==0.40.0
> django-cors-headers==3.1.1
> django-crispy-forms==1.7.2
> django-environ==0.4.5
> django-rest-auth==0.9.5
> django-rest-swagger==2.2.0
> djangorestframework==3.10.3
> djangorestframework-simplejwt==4.3.0
>

> === Reproduction
> It should be first mentioned that I am using DRF to provide API
> functionality for my views mentioned herein, and that I am using Docker
> both locally for development, and on the production server. The issue is
> reproducible in both environments.
>
> I should also note that I can avoid this behaviour by configuring the
> URLs in a different (what I presume to be the correct way)
>
> 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 app called **api** with a URL file, ```api/urls.py``` with the
> following
>
> ```path('case', CasesView.as_view(), name='all-cases'),```
>
> If you have a URL configured as above and ```APPEND_SLASH=True``` you
> will be able to navigate to the URL ```/api/v1/case/```. If
> ```APPEND_SLASH=False```, then navigating to the aforementioned URL, you
> will receive a 404 and Django debug will report that it tried a URL of
> ```/api/v1 case```
>
> In addition to what appears to be two slashes being rendered into the
> final URL, I am also curious as to where the blank space in the URL
> ```/api/v1 case``` comes from, as there is no whitespace in either of the
> two configured URLs.
>
> I can avoid this behaviour entirely, regardless of what
> ```APPEND_SLASH``` is set, by configuring the project URl as:
> ```path('api/v1/', include('api.urls')),```
>
> and the app URL as:
>
> ```path('case', CasesView.as_view(), name='all-cases'),```
>
> The difference only being in that I have hardcoded a trailing slash into
> the project URL's path.
>
> === Final Thoughts
>
> 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.
>
> However, 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, and I apologise if that is the case.
>
> I am only too happy to provide any further information that may be of use
> in investigating this issue, if indeed it turns out to be an issue.
>
> Cheers,
>
> Conor

New description:

 I'm not sure whether this is a feature or a bug, but failing in my attempt
 to get an answer in #django or django-users, I thought it best to report
 it.

 === Summary
 In short I have a URL which will be either ```/api/v1/case/``` if
 ```APPEND_SLASH=True,``` or ```/api/v1 case``` if ```APPEND_SLASH =
 False```.
 The URL ```/api/v1/case/``` is made up of two URLS, namely ```/api/v1```
 and ```/case```, one from the projects ```urls.py``` and the other from
 the app's ```urls.py```. What I suspect is happening is that a trailing
 slash is being appended to both the URLS before they are concatenated to
 make the final URL.

 **Django Version**: 2.2.6
 **Installed Apps**:
 django-allauth==0.40.0
 django-cors-headers==3.1.1
 django-crispy-forms==1.7.2
 django-environ==0.4.5
 django-rest-auth==0.9.5
 django-rest-swagger==2.2.0
 djangorestframework==3.10.3
 djangorestframework-simplejwt==4.3.0


 === Reproduction
 It should be first mentioned that I am using DRF to provide API
 functionality for my views mentioned herein, and that I am using Docker
 both locally for development, and on the production server. The issue is
 reproducible in both environments.

 I should also note that I can avoid this behaviour by configuring the URLs
 in a different (what I presume to be the correct way)

 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 app called **api** with a URL file, ```api/urls.py``` with the
 following

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

 If you have a URL configured as above and ```APPEND_SLASH=True``` you will
 be able to navigate to the URL ```/api/v1/case/```. If
 ```APPEND_SLASH=False```, then navigating to the aforementioned URL, you
 will receive a 404 and Django debug will report that it tried a URL of
 ```/api/v1 case```

 In addition to what appears to be two slashes being rendered into the
 final URL, I am also curious as to where the blank space in the URL
 ```/api/v1 case``` comes from, as there is no whitespace in either of the
 two configured URLs.

 I can avoid this behaviour entirely, regardless of what ```APPEND_SLASH```
 is set, by configuring the project URl as:
 ```path('api/v1/', include('api.urls')),```

 and the app URL as:

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

 The difference only being in that I have hardcoded a trailing slash into
 the project URL's path.

 === Final Thoughts

 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.

 However, 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, and I apologise if that is the case.

 I am only too happy to provide any further information that may be of use
 in investigating this issue, if indeed it turns out to be an issue.

 Cheers,

 Conor

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30895#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/073.d3d6e2d8685760dd37abbb52f062dc6d%40djangoproject.com.

Reply via email to