The Django framework has a strong bias in favor of trailing slashes in
URLs but not everyone wishes to set up their urls that way. If this
warning was to be respected, it's impossible to have urls without a
trailing slash in some situations:
{{{
# myapp. urls
urlpatterns = [
url(r'^dashboard', include('dashboard.urls')),
]
# dashboard.urls
urlpatterns = [
url(r'^$', views.dashboard_home, name='dashboard_home'),
url(r'^/users$', views.users, name='dashboard_users'),
]
}}}
The above URLconfs allow to have the URLs /dashboard and /dashboard/users
but it will produce the warning.
When trying to make the slash optional in the root URLconf with
{{{r'^dashboard/?'}}}, the 2nd url will reverse to /dashboardusers.
I know that some system checks can be silenced but I'd be in favor of the
complete removal of the check since it can be misleading for users who do
not wish trailing slashes in their URLs.
--
Ticket URL: <https://code.djangoproject.com/ticket/27238>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: alasdairnicol (added)
* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 0
Comment:
The original ticket is #23813. Maybe it's enough to disable the check if
`setting.APPEND_SLASH = False`?
--
Ticket URL: <https://code.djangoproject.com/ticket/27238#comment:1>
Comment (by alasdairnicol):
We could change the `check_resolver` method so that it passes the regex
when called recursively.
* If we call `check_resolver(resolver, r'^dashboard')` then we shouldn't
run `check_pattern_startswith_slash`. This would prevent the false
positives for strycore's example.
* If we call `check_resolver(resolver, r'^dashboard/')` or
`check_resolver(resolver, None)` (initial call) then it is ok to run
`check_pattern_startswith_slash`.
I haven't tried writing a patch for this yet. Modifying the check_resolver
method like this might be overly complex. I like the simplicity of
checking `settings.APPEND_SLASH` as Tim suggested.
--
Ticket URL: <https://code.djangoproject.com/ticket/27238#comment:2>
* stage: Unreviewed => Accepted
* easy: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27238#comment:3>
* status: new => assigned
* owner: nobody => alasdairnicol
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27238#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"911d9f4ed1a39f945769b7198a419850378f9824" 911d9f4e]:
{{{
#!CommitTicketReference repository=""
revision="911d9f4ed1a39f945769b7198a419850378f9824"
Fixed #27238 -- Disabled check_pattern_startswith_slash if
settings.APPEND_SLASH=False.
Thanks strycore for the report and timgraham for suggesting the
solution.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27238#comment:5>
Comment (by Tim Graham <timograham@…>):
In [changeset:"190cd0e49f967d2ec0b6c50a63f0d58d13319611" 190cd0e4]:
{{{
#!CommitTicketReference repository=""
revision="190cd0e49f967d2ec0b6c50a63f0d58d13319611"
[1.10.x] Fixed #27238 -- Disabled check_pattern_startswith_slash if
settings.APPEND_SLASH=False.
Thanks strycore for the report and timgraham for suggesting the
solution.
Backport of 911d9f4ed1a39f945769b7198a419850378f9824 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27238#comment:6>