[Django] #25035: urlresolvers.reverse doesn't resolve a namespaced URL when passed a callable

7 views
Skip to first unread message

Django

unread,
Jun 28, 2015, 11:41:21 PM6/28/15
to django-...@googlegroups.com
#25035: urlresolvers.reverse doesn't resolve a namespaced URL when passed a
callable
-------------------------------+--------------------
Reporter: adambrenecki | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
When I pass a view callable to `django.core.urlresolvers.reverse`, it
resolves correctly if the callable is in the top-level `urlpatterns`, or
one in a `urlpatterns` that's been `include`d without a namespace, but not
one that's been `include`d with a namespace.

I've noticed this behaviour in 1.7 and in the current HEAD of master (as
of 736fb1838cc25f5faf57cd2a4f6b6ab32ff9aadc).

Here's a minimal example (all files not listed are as generated by
`startproject`/`startapp`):

`testproj/urls.py`
{{{#!python
from django.conf.urls import url, include
from django.contrib import admin
import testapp.urls

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^testapp/', include(testapp.urls, namespace='testapp')),
]
}}}

`testapp/urls.py`
{{{#!python
from django.conf.urls import url, include
from django.contrib import admin
from . import views

urlpatterns = [
url(r'^myview', views.test),
]
}}}

`testapp/views.py`
{{{#!python
from django.shortcuts import render

# Create your views here.
def test():
pass
}}}

Which results in this:
{{{#!sh
> python manage.py shell
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.urlresolvers import reverse
>>> from testapp.views import test
>>> reverse(test)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/abrenecki/django/django/core/urlresolvers.py", line 602, in
reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view,
prefix, *args, **kwargs)))
File "/home/abrenecki/django/django/core/urlresolvers.py", line 510, in
_reverse_with_prefix
(lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'testapp.views.test' with arguments '()' and
keyword arguments '{}' not found. 0 pattern(s) tried: []
>>> exit()
}}}

If I remove the namespace, everything works as expected.

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

Django

unread,
Jun 29, 2015, 7:39:38 AM6/29/15
to django-...@googlegroups.com
#25035: urlresolvers.reverse doesn't resolve a namespaced URL when passed a
callable
------------------------------+--------------------------------------
Reporter: adambrenecki | Owner: nobody
Type: Bug | Status: closed
Component: Core (URLs) | Version: master
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* needs_better_patch: => 0
* component: Uncategorized => Core (URLs)
* needs_tests: => 0
* type: Uncategorized => Bug
* needs_docs: => 0
* resolution: => duplicate


Comment:

Duplicate of #17914

--
Ticket URL: <https://code.djangoproject.com/ticket/25035#comment:1>

Reply all
Reply to author
Forward
0 new messages