URL integration allows each SuperApp app to register its own URL patterns automatically. The framework discovers and executes URL extension functions from each app’s urls.py file during startup.
The core URL integration function is defined in src/django_superapp/urls.py:7-19:
def extend_superapp_urlpatterns(main_urlpatterns, package): for importer, modname, ispkg in pkgutil.iter_modules(package.__path__): submodule_name = f"{package.__name__}.{modname}.urls" try: urls_module = importlib.import_module(submodule_name) except ModuleNotFoundError as e: if f"No module named '{submodule_name}'" in str(e): continue raise e if hasattr(urls_module, "extend_superapp_urlpatterns"): urls_module.extend_superapp_urlpatterns(main_urlpatterns)
def extend_superapp_admin_urlpatterns(main_admin_urlpatterns, package): for importer, modname, ispkg in pkgutil.iter_modules(package.__path__): submodule_name = f"{package.__name__}.{modname}.urls" try: urls_module = importlib.import_module(submodule_name) except ModuleNotFoundError as e: if f"No module named '{submodule_name}'" in str(e): continue raise e if hasattr(urls_module, "extend_superapp_admin_urlpatterns"): urls_module.extend_superapp_admin_urlpatterns(main_admin_urlpatterns)
The extend_superapp_admin_urlpatterns function is deprecated and will be removed soon. The admin URL patterns are now generated in admin_portal/sites.py.
Django processes URL patterns in order. More specific patterns should come before more general ones.
# Good - specific before generalmain_urlpatterns += [ path('blog/create/', post_create), # Specific path('blog/<slug:slug>/', post_detail), # General]# Bad - general before specificmain_urlpatterns += [ path('blog/<slug:slug>/', post_detail), # Will match 'create' as a slug! path('blog/create/', post_create), # Never reached]
def extend_with_superapp_urlpatterns(main_urlpatterns, superapp_apps): extend_superapp_urlpatterns(main_urlpatterns, superapp_apps) # The below function is deprecated and will be removed soon extend_superapp_admin_urlpatterns(main_admin_urlpatterns, superapp_apps)
This wrapper function calls both standard and admin URL integration functions. Your main project URLs file would use this:
The framework handles missing urls.py files gracefully:
try: urls_module = importlib.import_module(submodule_name)except ModuleNotFoundError as e: if f"No module named '{submodule_name}'" in str(e): continue # App doesn't have urls.py - skip it raise e # Other import errors are raised
This means:
Apps without urls.py are silently skipped
Syntax errors or other import errors will still raise exceptions
You can list all registered URL patterns using Django management commands:
# List all URL patterns (if you have django-extensions)python manage.py show_urls# Or use the SuperApp commanddocker-compose exec web python3 manage.py list_all_urls_patterns