0

I have two apps under one project and decide to move these two apps under apps parent directory.
My current structure is,

project
  - app1 
  - app2
  - project
       - __init__.py
       - asgi.py
       - settings.py
       - urls.py
       - wsgi.py

New structure I am trying to have,

project
  - templates
  - static
  - apps
       - app1 
       - app2
  - project
       - __init__.py
       - asgi.py
       - settings.py
       - urls.py
       - wsgi.py

Following to this, How to keep all my django applications in specific folder
I edited my settings.py

from os.path import abspath, basename, dirname, join
BASE_DIR = dirname(dirname(abspath(__file)))
PROJECT_ROOT = dirname(__file__)
sys.path.insert(0, join(PROJECT_ROOT, 'apps'))

INSTALLED_APPS = [
    ....
    'apps.app1.apps.App1Config',
    'apps.app2.apps.App2Config',
]

I got an error that ModuleNOtFoundError: No module named 'app1'
Where should I have to edit to fix this issue?

jayko03
  • 2,329
  • 7
  • 28
  • 51

1 Answers1

1

to achieve this format

project
  - templates
  - static
  - apps
       - app1 
       - app2
  - project
       - __init__.py
       - asgi.py
       - settings.py
       - urls.py
       - wsgi.py

in the settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

and under apps folder create a new file __init__.py

and then back to settings.py, INSTALLED_APPS

INSTALLED_APPS = [
    ... # other apps

    'apps.app1',
    'apps.app2',

]

you can check one my project that uses this kind of format in here https://github.com/michaelhenry/localizr

Michael Henry
  • 644
  • 9
  • 12