[Django] #21899: Reverse does not work with function and namespace

4 views
Skip to first unread message

Django

unread,
Jan 29, 2014, 6:40:44 AM1/29/14
to django-...@googlegroups.com
#21899: Reverse does not work with function and namespace
-----------------------------+--------------------
Reporter: tonnzor | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
'''django.core.urlresolvers.reverse''' does not work with function and
namespace.

Example:

{{{
>>> from payment.views import *
>>> reverse('payment:payment.views.paypal_express_confirm') # resolve
using namespace and view path
'/payment/paypal_express/confirm/'

>>> paypal_express_confirm # check function is there
<function paypal_express_confirm at 0x39f7668>

>>> reverse(paypal_express_confirm) # try direct resolve
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "django/core/urlresolvers.py", line 476, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args,
**kwargs))
File "django/core/urlresolvers.py", line 396, in _reverse_with_prefix
"arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'payment.views.paypal_express_confirm' with
arguments '()' and keyword arguments '{}' not found.

>>> reverse(paypal_express_confirm, current_app='payment') # try with
current_app given
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/tonnzor/projects/reelport-
application/picturepipe/src/django/django/core/urlresolvers.py", line 476,
in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args,
**kwargs))
File "/home/tonnzor/projects/reelport-
application/picturepipe/src/django/django/core/urlresolvers.py", line 396,
in _reverse_with_prefix
"arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'payment.views.paypal_express_confirm' with
arguments '()' and keyword arguments '{}' not found.

>>> reverse(paypal_express_confirm, urlconf='payment.urls') # try app urls
without namespaces or something
'/paypal_express/confirm/'
}}}

Sure it works when you open '''/payment/paypal_express/confirm/'''

My project:

'''/urls.py:'''

{{{
from django.conf.urls import *

urlpatterns = patterns('',
url(r'^payment/', include('payment.urls', namespace='payment',
app_name='payment')),
)
}}}

'''payment/urls.py:'''
{{{
from django.conf.urls.defaults import *

urlpatterns = patterns('payment.views',
url(r'^paypal_express/confirm/$', 'paypal_express_confirm'),
)
}}}

'''payment/views.py:'''
{{{
from django.http import HttpResponse

def paypal_express_confirm(request):
return HttpResponse('Confirm')

}}}

Sorry, I didn't get hands to test on master -- but I'm pretty sure it is
still there.

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

Django

unread,
Jan 29, 2014, 6:52:17 AM1/29/14
to django-...@googlegroups.com
#21899: Reverse does not work with function and namespace
-----------------------------+--------------------------------------

Reporter: tonnzor | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.4
Severity: Normal | Resolution:
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 tonnzor):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

If you use view functions in '''payment/urls.py''' -- it works exactly the
same.


'''payment/urls.py''':
{{{
from django.conf.urls.defaults import *

from payment.views import *

urlpatterns = patterns('',
url(r'^paypal_express/confirm/$', paypal_express_confirm),
)
}}}

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

Django

unread,
Jan 29, 2014, 8:08:49 AM1/29/14
to django-...@googlegroups.com
#21899: Reverse does not work with function and namespace
-------------------------------------+-------------------------------------
Reporter: tonnzor | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* type: Bug => Cleanup/optimization
* component: Core (URLs) => Documentation


Comment:

Namespaces are designed to be used with URL names, which is a much better
way of reversing anyway. I don't think this should be changed, but perhaps
docs could be clarified?

--
Ticket URL: <https://code.djangoproject.com/ticket/21899#comment:2>

Django

unread,
Jan 29, 2014, 8:12:21 AM1/29/14
to django-...@googlegroups.com
#21899: Reverse does not work with function and namespace
-------------------------------------+-------------------------------------
Reporter: tonnzor | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by tonnzor):

But how could I reverse my view by function when using namespace?

Then why do we need current_app if it is not able to find view by it?

--
Ticket URL: <https://code.djangoproject.com/ticket/21899#comment:3>

Django

unread,
Jan 29, 2014, 8:13:37 AM1/29/14
to django-...@googlegroups.com
#21899: Reverse does not work with function and namespace
-------------------------------------+-------------------------------------
Reporter: tonnzor | Owner: nobody

Type: | Status: new
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by tonnzor):

Since Django always state that I could use function instead of its name
for routing (i.e. in urls.py, reverse and redirect) -- I assume it is a
bug that it cannot be used in combination with namespace. Not
documentation bug.

--
Ticket URL: <https://code.djangoproject.com/ticket/21899#comment:4>

Django

unread,
Feb 23, 2014, 4:41:02 AM2/23/14
to django-...@googlegroups.com
#21899: Reverse does not work with function and namespace
-------------------------------------+-------------------------------------
Reporter: tonnzor | Owner: nobody
Type: | Status: closed
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution: duplicate

Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #17914

--
Ticket URL: <https://code.djangoproject.com/ticket/21899#comment:5>

Django

unread,
Mar 4, 2014, 9:14:51 PM3/4/14
to django-...@googlegroups.com
#21899: Reverse does not work with function and namespace
-------------------------------------+-------------------------------------
Reporter: tonnzor | Owner: nobody

Type: | Status: closed
Cleanup/optimization | Version: 1.4
Component: Documentation | Resolution: duplicate
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by mrmachine):

Is this actually a duplicate? The original ticket is about passing
callable view functions to `reverse()`. This ticket is about passing a
dotted path reference to a view function, with a namespace, as a string.
With the original ticket, there is no way to specify a namespace. With
this ticket, a namespace is being specified.

--
Ticket URL: <https://code.djangoproject.com/ticket/21899#comment:6>

Reply all
Reply to author
Forward
0 new messages