# Nested urls inside the same app?

**URL:** <https://forum.djangoproject.com/t/nested-urls-inside-the-same-app/4980>\
**Category:** Using Django\
**Created:** [October 27, 2020, 11:57pm UTC](https://forum.djangoproject.com/t/nested-urls-inside-the-same-app/4980 "2020-10-27T23:57:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcorichetta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/marcorichetta/32/26473_2.png) [@marcorichetta](https://forum.djangoproject.com/u/marcorichetta)\
**Post date:** [October 27, 2020, 11:57pm UTC](https://forum.djangoproject.com/t/nested-urls-inside-the-same-app/4980/1 "2020-10-27T23:57:14Z")

</div>

Hi!

I wanted to be able to reverse nested urls inside the same app like:

```auto
reverse("products:regular:create") == /products/regular/new/

```

I found `include` can be passed an `app_namespace`, so I made that. ([Reference](https://docs.djangoproject.com/en/3.0/ref/urls/#include))

### products/urls.py

```auto
app_name = "products"

regulars_urlpatterns = [
    # /products/regular/create/
    path("new/", RegularProductCreateView.as_view(), name="create"),
]

urlpatterns = [
    # /products/...
    path("/", ProductListView.as_view(), name="list"),
    # /products/regular/...
    path("regular/", include((regulars_urlpatterns, "regular"))),
]

```

### Question

Is this right? Will there be some issue with this “hack”?  
I feel like I’m tricking Django into believing those urls belongs to a “regular” app.

Thanks!

---

<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:** [October 28, 2020, 5:34am UTC](https://forum.djangoproject.com/t/nested-urls-inside-the-same-app/4980/2 "2020-10-28T05:34:58Z")

</div>

Is there a reason why you think there’s something wrong with this? (What makes you think you’re “tricking” Django in some way?)

If it works the way you want (need) it to and doesn’t throw any errors (or warnings), then I’m not sure what you would be concerned about.

---

<div class="post-metadata">

**Author:** ![marcorichetta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/marcorichetta/32/26473_2.png) [@marcorichetta](https://forum.djangoproject.com/u/marcorichetta)\
**Post date:** [October 28, 2020, 1:06pm UTC](https://forum.djangoproject.com/t/nested-urls-inside-the-same-app/4980/3 "2020-10-28T13:06:24Z")

</div>

While writing this question I remembered that you once answered me something like “If it works for you, what is the problem”? 😅

I thought that because I’m passing “regular” as an `app_namespace`, but “regular” is not a Django app. ([Reference](https://docs.djangoproject.com/en/3.0/topics/http/urls/#term-application-namespace))

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [October 28, 2020, 3:45pm UTC](https://forum.djangoproject.com/t/nested-urls-inside-the-same-app/4980/4 "2020-10-28T15:45:05Z")

</div>

I agree with Ken. If it’s readable, works and makes your life easier it’s quality code.

---

<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:** [October 28, 2020, 3:51pm UTC](https://forum.djangoproject.com/t/nested-urls-inside-the-same-app/4980/5 "2020-10-28T15:51:41Z")

</div>

Ok, that’s what I was missing / not understanding from your question (“regular” not being a “real” app). Nothing strikes me as “wrong” about that, but it’s not something I think I’ve ever done.

(In reality, I tend to use the answer “if it works for you…” to cover the cases where I don’t see anything wrong and don’t envision any hidden edge cases that might cause problems in the future.)

---

<div class="post-metadata">

**Author:** ![marcorichetta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/marcorichetta/32/26473_2.png) [@marcorichetta](https://forum.djangoproject.com/u/marcorichetta)\
**Post date:** [October 28, 2020, 4:14pm UTC](https://forum.djangoproject.com/t/nested-urls-inside-the-same-app/4980/6 "2020-10-28T16:14:55Z")

</div>

I’m using it with no problems so far but, as it seems like an unexpected use, there may be things I’m not aware of.

Thanks for your comments @CodenameTim @KenWhitesell.
