Is it possible in Django to reverse URLs within a reusable app such that the reversing will still work if the app is nested with another? It's essentially the same question
as this stack overflow question but the answer there of moving the URLs into the root urlconf seems wrong to me. For example:
# app2 template
{% url 'app2:test' %}
# app2 urlconf
app_name = "app2"
urlpatterns = [
path("test", views.test_view.as_view(), name="test"),
]
# app1 urlconf
app_name = "app1"
urlpatterns = [
path("", include("app2.urls")),
]
# root urlconf
urlpatterns = [
path("", include("app1.urls")),
]
Attempting to render the app2 template currently results in a NoReverseMatch due to "app2" not being a registered namespace. If the app2 template is overridden in app1 to instead use:
{% url 'app1:app2:test' %}
the reverse issue goes away. It seems like there should be a way to mitigate this issue without overriding the app2 template in app1.
Is it not a valid use case for reusable apps to nest the url patterns of other reusable apps within themselves without expecting to have to override all places where a URL reverse is done in the nested reusable app?