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.
* 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>
* 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>
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>
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>
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #17914
--
Ticket URL: <https://code.djangoproject.com/ticket/21899#comment:5>
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>