I'm trying to get the hang of Django URL namespaces. But I can't find any examples or documentation.
Here is what I have tried.
urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^foo/', include('sub_urls', namespace='foo', app_name='foo')),
(r'^bar/', include('sub_urls', namespace='bar', app_name='bar')),
)
sub_urls.py:
from django.conf.urls.defaults import patterns, url
from views import view1
urlpatterns = patterns('views',
url(r'^(?P<view_id>\d+)/$', view1, name='view1')
)
views.py:
from django.shortcuts import render_to_response
def view1(request, view_id):
return render_to_response('view1.html', locals())
In view1.html, {% url foo:view1 3 %} outputs /foo/3, and {% url bar:view1 3 %} outputs /bar/3. This holds true whether I browse to /foo/X or /bar/X.
What I want is to be able to browse to /foo/X or /bar/X, and have {% url view1 3 %} output either /foo/3 or /bar/3, respectively.