Can we define Class with urlpatterns attribute with multiple version based code

class ApiV1:
    urlpatterns = (
        path("auth/", include("v1.user.urls")),
        path("doctor/", include("v1.doctor.urls")),
        path("patient/", include("v1.patient.urls")),
    )


class ApiV2:
    urlpatterns = (
        path("auth/", include("v2.user.urls")),
        path("doctor/", include("v2.doctor.urls")),
        path("patient/", include("v2.patient.urls")),
    )


urlpatterns = i18n_patterns(
    path("admin/", admin.site.urls),
    path('api/v1/', include(ApiV1)),
    path('api/v2/', include(ApiV2)),
    prefix_default_language=False,
)

I have to use version-based code in Django, URL and View are also different for each version code, So want to confirm it is a good way? because I checked this is working fine with both api/v1 and api/v2 URLs. There is just Class I defined but according to Django include method it’s accepting module or URLs not Class inside.

You can use the show_urls command from within the Django extensions package to see how Django is going to interpret your definitions.

You can just include the list of urls, there’s no need for the class or urlpatterns attribute. https://docs.djangoproject.com/en/4.2/topics/http/urls/#including-other-urlconfs has a good example of this with the “extra_patterns”