#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.

-- 
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/055.b2eb06acfd4685afe0b4db0a448ae704%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to