#24904: reverse() doesn't allow for nested current_app namespaces
-----------------------------+--------------------
Reporter: knbk | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
`reverse()` doesn't split the `current_app` on `:` like it does for
namespaces in the `viewname`. It directly compares a single namespace
"level" to the full `current_app` variable. Take the following urlconf:
{{{
blog_patterns = [
url(r'^comments-one/', include('comments.urls', 'comments-one',
'comments')),
url(r'^comments-two/', include('comments.urls', 'comments-two',
'comments')),
]
urlpatterns = [
url(r'^blog-one/', include(blog_patterns, 'blog-one', 'blog')),
url(r'^blog-two/', include(blog_patterns, 'blog-two', 'blog')),
]
}}}
To reverse urls for `blog-one:comments-one`, without hard-coding the
instance namespace in `viewname`, you might assume this would work:
{{{
reverse('blog:comments:view_name', current_app='blog-one:comments-one')
}}}
However, `'blog-one:comments-one'` doesn't compare equal to either
`'blog-one'` or `'comments-one'`, so it will use the default namespace for
each namespace nesting level instead, and return `/blog-two/comments-
two/...`.
This also means that this example in the docs won't work for nested
namespaces:
{{{
def render_to_response(self, context, **response_kwargs):
self.request.current_app = self.request.resolver_match.namespace
return super(DetailView, self).render_to_response(context,
**response_kwargs)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24904>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/047.318f71b0c2ed279da29f43eee29dd985%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.