# Routing with multiple applications failing

**URL:** <https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418>\
**Category:** Using Django\
**Created:** [August 27, 2021, 12:43pm UTC](https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418 "2021-08-27T12:43:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlewin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dlewin/32/1057_2.png) [@dlewin](https://forum.djangoproject.com/u/dlewin)\
**Post date:** [August 27, 2021, 12:43pm UTC](https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418/1 "2021-08-27T12:43:24Z")

</div>

hi,  
I have followed the [Bezcoder DRF / CRUD tutorial](https://www.bezkoder.com/django-rest-api/) with the informations from the “Django for APis” book of William Vincent.  
While I have 1 project containing 1 app : it’s ok. I can curl the API fine.

The problem came after I’ve added a 2nd application: an errr is coming because I think Django can’t know which view belongs to which app: app1 or app2

> api/urls.py line 9 in …  
> url(r’^app1$', views.app1\_list),  
> AttributeError : module ‘App2.views’ has no attribute ‘app1\_list’

```auto
from django.urls import path
from django.conf.urls import url
from .views import app1APIView, app2APIView
from app1 import views
from app2 import views

urlpatterns = [
    path('', app2APIView.as_view()),
    url(r'^app1$', views.app1_list),
    url(r'^app1/(?P<pk>[0-9]+)$', views.app1_detail),
    url(r'^app1/enabled$', views.app1_list_enabled),
    url(r'^app2$', views.app2_list),
    url(r'^app2/(?P<pk>[0-9]+)$', views.app2_detail),
    url(r'^app2/enabled$', views.app2_list_enabled)

```

This code is working only if I comment app1 or app2 but not both

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 27, 2021, 1:45pm UTC](https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418/2 "2021-08-27T13:45:22Z")

</div>

You’ve got a couple different ways of handling this.

My recommendation would be to just import app1.views and app2.views, and prefix your urls with the corresponding app name:  
`url('^app1$', app1.views.app1_list),`

---

<div class="post-metadata">

**Author:** ![dlewin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dlewin/32/1057_2.png) [@dlewin](https://forum.djangoproject.com/u/dlewin)\
**Post date:** [August 27, 2021, 3:48pm UTC](https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418/3 "2021-08-27T15:48:31Z")

</div>

Thanks @KenWhitesell for you answer.  
However, doing

> from django.urls import path  
> from django.conf.urls import url
> 
> # from .views import app1APIView, app2APIView
> 
> from app1 import views  
> from app2 import views
> 
> urlpatterns = [  
> #path(‘’, app2APIView.as\_view()),  
> url(r’^app1$‘, app1.views.app1\_list),  
> url(r’^app1/(?P[0-9]+)$‘, app1.views.app1\_detail),  
> url(r’^app1/enabled$‘, app1.views.app1\_list\_enabled),  
> url(r’^app2$‘, app1.views.app2\_list),  
> url(r’^app2/(?P[0-9]+)$‘, app1.views.app2\_detail),  
> url(r’^app2/enabled$', app1.views.app2\_list\_enabled)

ends with error _" app1 is not defined"_  
while commenting all the app2 references and not prefixing app1 but just :

> urlpatterns = [  
> #path(‘’, app2APIView.as\_view()),  
> url(r’^app1$‘, views.app1\_list),  
> url(r’^app1/(?P[0-9]+)$‘, views.app1\_detail),  
> url(r’^app1/enabled$‘, views.app1\_list\_enabled),  
> #url(r’^app2$‘, app1.views.app2\_list),  
> #url(r’^app2/(?P[0-9]+)$‘, app1.views.app2\_detail),  
> #url(r’^app2/enabled$', app1.views.app2\_list\_enabled)

is ok.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 27, 2021, 4:07pm UTC](https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418/4 "2021-08-27T16:07:47Z")

</div>

I think you overlooked this part of my answer:

> [@KenWhitesell](#):
>
> My recommendation would be to just import app1.views and app2.views,

---

<div class="post-metadata">

**Author:** ![dlewin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dlewin/32/1057_2.png) [@dlewin](https://forum.djangoproject.com/u/dlewin)\
**Post date:** [August 30, 2021, 7:58am UTC](https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418/5 "2021-08-30T07:58:30Z")

</div>

OK but if I do that

> “url is not defined”

arizes which is normal.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 30, 2021, 9:32am UTC](https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418/6 "2021-08-30T09:32:32Z")

</div>

My fault, my previous reply wasn’t clear. You still need your other imports. What you need to change is the `from app1 import views` to `import app1.views` (and the same for app2)

---

<div class="post-metadata">

**Author:** ![dlewin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dlewin/32/1057_2.png) [@dlewin](https://forum.djangoproject.com/u/dlewin)\
**Post date:** [August 30, 2021, 9:46am UTC](https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418/7 "2021-08-30T09:46:43Z")

</div>

@KenWhitesell no fault is in play when it’s about helping.

And by the way, this solves the issue.  
thanks I have been searching in many (wrong it seems) places for this.

Tell me if I have to change the title or something to mark it as solved.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 30, 2021, 9:50am UTC](https://forum.djangoproject.com/t/routing-with-multiple-applications-failing/9418/8 "2021-08-30T09:50:56Z")

</div>

There should be an icon underneath each reply that you can click to select the solution. Find the reply you wish to mark, and click the “solution” box.
