Nested Namespaces don't Reverse

9 views
Skip to first unread message

james...@gmail.com

unread,
Jan 6, 2010, 2:26:03 AM1/6/10
to Django developers
I have a simple example that is giving me some trouble. When a project
has multiple instances of an application referenced by patterns nested
more than one level deep it seems impossible to look up using reverse
() with only two path components. No matter what the current_app
argument is set to.

After looking at django internals this seems to be by design. However
it makes nesting of namespaces somewhat difficult to deploy because
there isn't a dynamic way to construct URLs based on contextual
information in your application.

Here is my urlpatterns to test:

patterns2 = (patterns('views',
url(r'^$', 'index', name='index'),
), 'app', 'inst2')


patterns1 = (patterns('views',
url(r'^$', 'index', name='index'),
url(r'^instance2/', include(patterns2)),
), 'app', 'inst1')


urlpatterns = patterns('views',
url(r'^$', 'index', name='crm'),
url(r'^instance1/', include(patterns1)),

)


and the view that I was testing with:
def index(request):
print reverse('app:index', current_app='inst2') #busted, should
return /instance1/instance2/, not /instance1/
print reverse('app:index', current_app='inst1') #works, /
instance1/
print reverse('inst1:app:index') #works, should it?, /instance1/
instance2/
print reverse('inst1:inst2:index') #works, /instance1/instance2/
print reverse('app:index') #default instance, current_app should
change behavior
return HttpResponse('Try the console')


In an application where there are multiple instances responding on
many different urls nested amongst each other, it becomes impossible
to generate reverse() urls since you don't know your current
namespace.

To illustrate, generating the string 'inst1:inst2:index' at runtime
from within the application would be mostly impossible.

Reply all
Reply to author
Forward
0 new messages