I have added a router property (an instance of DRF's SimpleRouter) to my AppConfig. I want to get a list of all installed apps in my urls.py file and add any app with the router property to my url patterns.
This is my urls.py file:
from django.conf.urls import url, include
from django.contrib import admin
from django.apps import apps
urlpatterns = [
url(r'^admin/', include(admin.site.urls))
]
# Loading the routers of the installed apps and core apps
for app in apps.get_app_configs():
if hasattr(app, 'router'):
urlpatterns += app.router.urls
and this is an example of my modified AppConfig:
from django.apps import AppConfig
from .router import auth_router
class AuthConfig(AppConfig):
name = "core.auth"
# to avoid classing with the django auth
label = "custom_auth"
# router object
router = auth_router
def ready(self):
from .signals import user_initialize, password_reset_set_token
default_app_config = 'core.auth.AuthConfig'
When I try the above solution, I end up getting a "django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet." error message!
I've tried using the solutions proposed here but none of them worked!