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.
-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.


Reply via email to