# Some question about nested url namespaces

**URL:** <https://forum.djangoproject.com/t/some-question-about-nested-url-namespaces/26358>\
**Category:** Forms & APIs\
**Created:** [December 22, 2023, 10:50am UTC](https://forum.djangoproject.com/t/some-question-about-nested-url-namespaces/26358 "2023-12-22T10:50:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HairlessVillager](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hairlessvillager/32/16144_2.png) [@HairlessVillager](https://forum.djangoproject.com/u/HairlessVillager)\
**Post date:** [December 22, 2023, 10:50am UTC](https://forum.djangoproject.com/t/some-question-about-nested-url-namespaces/26358/1 "2023-12-22T10:50:48Z")

</div>

Hi! I’ve read [a post about nested urls](https://forum.djangoproject.com/t/nested-urls-inside-the-same-app/4980), and I have another similar question: what’s the best practice for nested url namespaces? And why name the argument `app_namespace` while it also accept a non-app namespace?🤔BTW I’m using this code to namespace nested urls:

```python
# you can access url "service/exam/student/" to call the views.service_exam_student()
# also reverse("service:exam:student") returns "service/exam/student/"

# exam.py
student_patterns = [
    path("student/", views.service_exam_student, "student"),
]

# urls.py
service_patterns = [
    path("exam/", include((exam_patterns, "exam"))),
]
urlpatterns = [
    # ...
    path("service/", include((service_patterns, "service"))),
    # ...
]

```

---

<div class="post-metadata">

**Author:** ![HairlessVillager](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hairlessvillager/32/16144_2.png) [@HairlessVillager](https://forum.djangoproject.com/u/HairlessVillager)\
**Post date:** [December 22, 2023, 10:53am UTC](https://forum.djangoproject.com/t/some-question-about-nested-url-namespaces/26358/2 "2023-12-22T10:53:34Z")

</div>

I means, why not let them have a common style like:

```python
# exam.py
student_patterns = [
    path("student/", views.student, "student"),
]

# urls.py
service_patterns = [
    path("exam/", include(exam_patterns), "exam"),
]
urlpatterns = [
    # ...
    path("service/", include(service_patterns), "service"),
    # ...
]

```

---

<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:** [December 22, 2023, 12:49pm UTC](https://forum.djangoproject.com/t/some-question-about-nested-url-namespaces/26358/3 "2023-12-22T12:49:22Z")

</div>

I’m not following what you’re asking here.

But the difference in the two cases is that in the first case, the quoted values “exam” and “service” contained within the include statement become part of the url’s named namespace, while in the second version it doesn’t.

See the docs at:

- [django.urls functions for use in URLconfs | Django documentation | Django](https://docs.djangoproject.com/en/5.0/ref/urls/#include)  
and
- [URL dispatcher | Django documentation | Django](https://docs.djangoproject.com/en/5.0/topics/http/urls/#url-namespaces)

---

<div class="post-metadata">

**Author:** ![HairlessVillager](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hairlessvillager/32/16144_2.png) [@HairlessVillager](https://forum.djangoproject.com/u/HairlessVillager)\
**Post date:** [December 24, 2023, 1:23pm UTC](https://forum.djangoproject.com/t/some-question-about-nested-url-namespaces/26358/4 "2023-12-24T13:23:19Z")

</div>

Please excuse the late reply😭 Thank you very very much for your helpful reply. I’ve read the documents you listed, and I have also searched on the Internet, which taught me a lot. I realized this question is not good. Sorry😥 I will read more before asking.
