0

My setup include django 3.0 , my directory structure is:

/webapp/
      api_1/app1/models.py
      
      api_2/app1/models.py

The api_1 used multiple db which are configured by db routing. i want to import the api_2.app1.ModelA in my api_1.views. i have tried to add the sys.path.append('/webapp/api_2') in api_2.wsgi, add the api_2.app1 in the INSTALLED_APPS of api_1 but still getting error of cannot found Module api_2. i have also tried reverse of it but cannot import that also.

  • how does your regular import statment look like? `from api_2.app1.models import *`? I am a bit confused, are those two different django apps or django projects with own settings file etc? – hansTheFranz Aug 10 '20 at 14:14
  • @hansTheFranz yes these are two different projects with their own settings. my import statement looks like exactly you have defined – Shavzz Hussain Aug 10 '20 at 14:44
  • 1
    You can import classes from other projects, in the end they are all python classes and can be used in other python projects.have a look at this https://stackoverflow.com/questions/14509192/how-to-import-functions-from-other-projects-in-python . If you want to do this in a production enviroment I would sugest to look into micro services and how to exchange data between two servers via restapi or whatever... – hansTheFranz Aug 12 '20 at 15:15

0 Answers0