Reputation: 281
What I have:
Django Project
that is acting as a REST API through Django Rest Framework.Django Apps
that are controlling the logic of my Postgres DB.What I am trying to do:
Django App
that represents a Service / Integration
with RobinhoodsubApplications
in order to separate all logic for a user
vs a transactions
vs a transfers
etc ...Django App
& all subApplications
are APIs ONLY ... they will never need models / migrations
but they will eventually communicate with the other Django Apps
CODE STRUCTURE:
Django Project
├── 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')
]
Error I am getting:
SERVICE_robinhood/urls.py", line 23
...
ModuleNotFoundError: No module named 'user'
I am assuming that this is an issue with how I am importing the sub application into the overall app but have added all the relevant code I can think of to uncover any other problems.
Upvotes: 0
Views: 137
Reputation: 281
Per Amine's answer (ProfileLink) do the following in your Django App
to import a subApplications
routes:
SERVICE_robinhood.urls.py
urlpatterns = [
path('user/', include('SERVICE_robinhood.user.urls')),
]
Upvotes: 1