Dmitry Oleinik
Dmitry Oleinik

Reputation: 710

Three apps one namespace

What I am trying to do is to have common namespace for two or more apps.

Lets say I have an apps folder with 3 apps in it: dashboard (admin panel to display other apps), clients (displays fancy tables), and orders (same as clients). Looks like this:

--  apps
    |-- dashboard
    |   |-- views.py
    |   |-- models.py
    |   |-- urls.py
    |-- clients
    |   |-- views.py
    |   |-- models.py
    |   |-- urls.py
    |-- orders
    |   |-- views.py
    |   |-- models.py
    |   |-- urls.py

In my main urls.py I have:

url(r'^dashboard/', include('apps.dashboard.urls',
                                namespace='dashboard',
                                app_name='dashboard')),

In dashboard/urls.py:

url(r'^clients/', include('apps.clients.urls')),
url(r'^orders/', include('apps.orders.urls')),

And in clients:

url(r'^$', views.AllClientsList.as_view(), name='clients-all'),

So, I'd like to have the same namespace for urls in clients and orders app, to use them as {% url "dashboard:clients-all" %}. But it simply doesn't work - NoReverseMatch: Reverse for 'customers_detailed' not found. 'customers_detailed' is not a valid view function or pattern name.

Is there any way to do it?

Update: Links like <a href='{% url 'dashboard:customers-all' %}'>Customers</a> throw erroes "Reverse for 'customers-all' not found. 'customers-all' is not a valid view function or pattern name." urls.py

 urlpatterns = [ url(r'^dashboard/', include('apps.dashboard.urls')), ] 

apps/dashboard/urls.py

 app_name = 'dashboard'
 urlpatterns = [ url(r'^customers/', include('apps.customers.urls')), ] 

apps/customers/urls.py

 app_name = 'customers'
 urlpatterns = [ url(r'^$', views.AllCustomerList.as_view(), name='customers-all'), ] 

Upvotes: 1

Views: 62

Answers (1)

Alasdair
Alasdair

Reputation: 308879

Since your dashboard urls includes the customers urls, you need to include the nested namespace:

{% url 'dashboard:customers:customers-all' %}

Upvotes: 1

Related Questions