setting up a Django project under PyCharm


I am developing my first Django project. I am using Django 3.0 and developing with PyCharm Community Edition.

My problem is simple problem of setting up the project under PyCharm :

This Django project is part of a bigger python project (lets’ call it big_project) with modules that run in batches. Hence, my folder structure under PyCharm is as follows :

             |-- logs/
             |-- psql_scripts/
             |-- resources/
             |-- src/
                   |-- big_project/
                             |-- django/
                                    |-- my_django_project/
                                             |-- my_django_project/
                                             |-- another_django_app/
                             |-- batches/
                                    |-- some_modules/
                                             |-- submodules/
                             |-- utils/

As you can see, my main django app is located in src/big_project/django/my_django_project/my_django_project .

I guess my problem stems from the fact that, while my python root folder is src/, Django would normally use as python root my_django_project/ .

It causes troubles with the python import statements and differences of behavior between coding under PyCharm and runtime (“python runserver”) :

  • If I want to import something from the module big_project/batches/some_modules/ , PyCharm will import successfully if I code
    from big_project.batches.some_modules.module1 import something

  • But that does not work at runtime.

PyCharm and the Django server seem to have different root folders.
How was I suppose to set up this project and how do I solve this ?

PS : in the module , I have

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_django_project.settings')