带有子应用程序的 Django 路由

Django Routing w/ subApplication

我有:

我想做什么:


代码结构:

├── APP_holdings
├── APP_logs
├── APP_unique
├── APP_users
├── ⭐️⭐️ DJANGO
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-38.pyc
│   │   └── wsgi.cpython-38.pyc
│   ├── asgi.py
│   ├── fixtures
│   │   ├── platforms.json
│   │   └── symbols.json
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── EXAMPLE.env
├── Pipfile
├── Pipfile.lock
├── Procfile
├── README.md
├── ⭐️⭐️ SERVICE_robinhood
│   ├── README.md
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── models.py
│   ├── tests.py
│   ├── urls.py
│   ├── ⭐️⭐️ user
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── api
│   │   │   ├── __init__.py
│   │   │   └── login.py
│   │   ├── apps.py
│   │   ├── urls.py
│   │   └── utils.py
│   │       ├── __init__.py
│   │       └── printSomething.py
│   └── views.py
├── manage.py
├── requirements.txt
├── static
│   └── __init__.py
└── staticfiles

SETTINGS.py

INSTALLED_APPS = [
    # Pre Installed
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Apps
    'APP_users.apps.AppUserConfig',
    'APP_holdings.apps.AppHoldingsConfig',
    'APP_logs.apps.AppLogsConfig',
    'APP_unique.apps.AppUniqueConfig',

    # !!! --- I AM ASSUMING I AM IMPORTING THE APP INCORRECTLY (and have tried many different ways mentioned on various SO threads -> See `.apps` code --- !!!
    'SERVICE_robinhood.apps.ServiceRobinhoodConfig',
    'SERVICE_robinhood.user.apps.UserConfig',

    # Helpers
    'corsheaders',

    # Django Rest Framework
    'rest_framework',
    'rest_framework.authtoken',
]

SERVICE_robinhood/apps.py

class ServiceRobinhoodConfig(AppConfig):
    name = 'SERVICE_robinhood'

SERVICE_robinhood/user/apps.py

class UserConfig(AppConfig):
    # name = 'user'
    name = 'SERVICE_robinhood.user'

DJANGO.urls.py

urlpatterns = [
    path('admin/', admin.site.urls),

    # ...auth...

    path('user/', include('APP_users.urls')),
    # ...otherApps...

    path('RH/', include('SERVICE_robinhood.urls'))
]

SERVICE_robinhood/urls.py

# ?? do I need to import user here and pass it differently into `include` ??
# I thought that since `users` should be a module in and of itself in the overall Django Project you could just reference the app by name

urlpatterns = [
    ❌ path('user/', include('user.urls')),
    ✅ UPDATE - FROM ANSWER: ✅ path('user/', include('SERVICE_robinhood.user.urls')),
]

SERVICE_robinhood/user/urls.py

from . import utils
urlpatterns = [
    path('printSomething/', utils.printSomething, name='printSomething')
]

我得到的错误:

SERVICE_robinhood/urls.py", line 23
...
ModuleNotFoundError: No module named 'user'

我假设这是我将子应用程序导入整个应用程序的方式的问题,但我已经添加了我能想到的所有相关代码以发现任何其他问题。

根据 Amine 的回答 (ProfileLink),在您的 Django App 中执行以下操作以导入 subApplications 路由:

SERVICE_robinhood.urls.py

urlpatterns = [
    path('user/', include('SERVICE_robinhood.user.urls')),
]