0

I have an existing project (let's name it main) on Django and several applications in it. There is a separate project, also in django, and one application inside it (we will call this the second one). Here is a generalized file structure for project "second":

my_second_project
│   manage.py
│   models.py
│   my_models.py
│   my_views.py
│
├───myapp
│   │   admin.py
│   │   apps.py
│   │   Funcs.py
│   │   models.py
│   │   tests.py
│   │   urls.py <-- from here urls import to project urls file
│   │   views.py
│   │   __init__.py
│   │
│   ├───migrations
│   │   └───...│
├───my_second_project
│   │   asgi.py
│   │   settings.py
│   │   urls.py <-- HERE all urls i need
│   │   wsgi.py
│   │   __init__.py
├───templates
│       ...
│
└───__pycache__
        models.cpython-37.pyc

Here is a generalized file structure for project "main":

main_project
├───app ...
│   ├───...
├───main_project
│   ├───media
│   │   └───user_uploads
│   ├───settings
│   │   └───base.py
│   └───urls.py
├───app ...
│   ├───...
├───app ...
│   ├───...
└───static
    ├...

I need to integrate "second" project into my existing one (main project), ideally without making any changes to the second project. I tried to do it in the same way that applications are integrated (via urls include), but it seems that it does not work with projects because django writes "myapp module not found".

url('data-classifier/', include('my_second_project.my_second_project.urls'))

Is there some way to add a "second" project to my "main" project without changing the "second" one?

Ivas1256
  • 33
  • 1
  • 6

1 Answers1

-1

When you deploy these projects they won't be stored in directories nearby. Ideally they won't be on the same server at all.

Instead if you can't afford to copy (or move) contents of the app you need from second to main project, and you don't want to redirect with nginx, make a small app in your main project and from urls.py redirect to endpoints of second.

main_project.my_second_project.urls.py

from django.urls import path
from django.views.generic import RedirectView

app_name = 'my_second_project'
urlpatterns = [
    path('endpoint/', RedirectView.as_view(url='<my_second_project_url>'), name='endpoint')
]

If you're running main locally at 8000, and second at 8001, then you'd put 'http://localhost:8001/endpoint/' as url up there.

Kyryl Havrylenko
  • 674
  • 4
  • 11