title: How do you use Django URL namespaces?
body: <p>I'm trying to get the hang of <a href="http://docs.djangoproject.com/en/dev/topics/http/urls/#defining-url-namespaces" rel="noreferrer">Django URL namespaces</a>. But I can't find any examples or documentation.</p>
  
  <p>Here is what I have tried.</p>
  
  <p>urls.py:</p>
  
  <pre><code>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')),            
  )
  </code></pre>
  
  <p>sub_urls.py:</p>
  
  <pre><code>from django.conf.urls.defaults import patterns, url
  from views import view1
  
  urlpatterns = patterns('views',
      url(r'^(?P&lt;view_id&gt;\d+)/$', view1, name='view1')
  )
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>from django.shortcuts import render_to_response
  
  def view1(request, view_id):
      return render_to_response('view1.html', locals())
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>