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.