I have a simple Django project (namely the one from this tutorial).
The main part of the tree looks like this:
.
├── env
├── proj
│ ├── proj
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── api
│ │ ├── __init__.py
│ │ ├── serializers.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── base
│ │ ├── __init__.py
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── models.py
│ │ ├── tests.py
│ │ └── views.py
│ └── manage.py
├── __init__.py
└── README.md
In the tutorial the outer proj
folder is the root.
In api/views.py is the following import: from base.models import Item
When I print sys.path
in settings.py, it contains /path/to/wrapper/proj
.
But I would like my root folder to be one level higher.
This is what I did:
- go to Settings > Project structure and change content root to
/path/to/wrapper
- append another
.parent
toBASE_DIR
in settings.py
(nowBASE_DIR = Path(__file__).resolve().parent.parent.parent
) - prepend
proj.
to imports
(nowfrom proj.base.models import Item
)
But that does not work: ModuleNotFoundError: No module named 'proj.base'
When I print sys.path
in settings.py, it still contains /path/to/wrapper/proj
instead of /path/to/wrapper
.
Where does that actually come from? And how can I change it?
(Apparently the content root in the settings is only for syntax highlighting and code completion.)