ModuleNotFoundError: No module named 'mysite.settings' - Django project

109 Views Asked by At

I inherited a Django project that another team of students were working on a couple of years ago. I have been trying to run the project using py manage.py runserver but that doesn't work. Instead, I get the following error: ModuleNotFoundError: No module named 'mysite.settings. Note, in the project folder there's no settings.py file which could be the problem.

Does anyone have ideas why this is happening and how to solve it?

I tried editing the wsgi.py file but that was not useful because there is no settings app.

├───.vscode
└───mysite
    ├───.idea
    │   └───inspectionProfiles
    ├───mysite
    │   └───__pycache__
    ├───templates
    │   └───treeID
    ├───treeID
    │   ├───.vs
    │   │   └───treeID
    │   │       └───v16
    │   ├───migrations
    │   │   └───__pycache__
    │   └───__pycache__
    └───virt
        ├───Include
        ├───Lib
        │   └───site-packages
        │       ├───pip
        │       │   ├───_internal
        │       │   │   ├───cli
        │       │   │   │   └───__pycache__
        │       │   │   ├───commands
        │       │   │   │   └───__pycache__
        │       │   │   ├───distributions
        │       │   │   │   └───__pycache__
        │       │   │   ├───index
        │       │   │   │   └───__pycache__
        │       │   │   ├───locations
        │       │   │   │   └───__pycache__
        │       │   │   ├───metadata
        │       │   │   │   ├───importlib
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───models
        │       │   │   │   └───__pycache__
        │       │   │   ├───network
        │       │   │   │   └───__pycache__
        │       │   │   ├───operations
        │       │   │   │   ├───build
        │       │   │   │   │   └───__pycache__
        │       │   │   │   ├───install
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───req
        │       │   │   │   └───__pycache__
        │       │   │   ├───resolution
        │       │   │   │   ├───legacy
        │       │   │   │   │   └───__pycache__
        │       │   │   │   ├───resolvelib
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───utils
        │       │   │   │   └───__pycache__
        │       │   │   ├───vcs
        │       │   │   │   └───__pycache__
        │       │   │   └───__pycache__
        │       │   ├───_vendor
        │       │   │   ├───cachecontrol
        │       │   │   │   ├───caches
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───certifi
        │       │   │   │   └───__pycache__
        │       │   │   ├───chardet
        │       │   │   │   ├───cli
        │       │   │   │   │   └───__pycache__
        │       │   │   │   ├───metadata
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───colorama
        │       │   │   │   ├───tests
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───distlib
        │       │   │   │   └───__pycache__
        │       │   │   ├───distro
        │       │   │   │   └───__pycache__
        │       │   │   ├───idna
        │       │   │   │   └───__pycache__
        │       │   │   ├───msgpack
        │       │   │   │   └───__pycache__
        │       │   │   ├───packaging
        │       │   │   │   └───__pycache__
        │       │   │   ├───pkg_resources
        │       │   │   │   └───__pycache__
        │       │   │   ├───platformdirs
        │       │   │   │   └───__pycache__
        │       │   │   ├───pygments
        │       │   │   │   ├───filters
        │       │   │   │   │   └───__pycache__
        │       │   │   │   ├───formatters
        │       │   │   │   │   └───__pycache__
        │       │   │   │   ├───lexers
        │       │   │   │   │   └───__pycache__
        │       │   │   │   ├───styles
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───pyparsing
        │       │   │   │   ├───diagram
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───pyproject_hooks
        │       │   │   │   ├───_in_process
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───requests
        │       │   │   │   └───__pycache__
        │       │   │   ├───resolvelib
        │       │   │   │   ├───compat
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───rich
        │       │   │   │   └───__pycache__
        │       │   │   ├───tenacity
        │       │   │   │   └───__pycache__
        │       │   │   ├───tomli
        │       │   │   │   └───__pycache__
        │       │   │   ├───urllib3
        │       │   │   │   ├───contrib
        │       │   │   │   │   ├───_securetransport
        │       │   │   │   │   │   └───__pycache__
        │       │   │   │   │   └───__pycache__
        │       │   │   │   ├───packages
        │       │   │   │   │   ├───backports
        │       │   │   │   │   │   └───__pycache__
        │       │   │   │   │   └───__pycache__
        │       │   │   │   ├───util
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───webencodings
        │       │   │   │   └───__pycache__
        │       │   │   └───__pycache__
        │       │   └───__pycache__
        │       ├───pip-23.2.1.dist-info
        │       ├───pkg_resources
        │       │   ├───extern
        │       │   │   └───__pycache__
        │       │   ├───_vendor
        │       │   │   ├───importlib_resources
        │       │   │   │   └───__pycache__
        │       │   │   ├───jaraco
        │       │   │   │   ├───text
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───more_itertools
        │       │   │   │   └───__pycache__
        │       │   │   ├───packaging
        │       │   │   │   └───__pycache__
        │       │   │   ├───pyparsing
        │       │   │   │   ├───diagram
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   └───__pycache__
        │       │   └───__pycache__
        │       ├───setuptools
        │       │   ├───command
        │       │   │   └───__pycache__
        │       │   ├───config
        │       │   │   ├───_validate_pyproject
        │       │   │   │   └───__pycache__
        │       │   │   └───__pycache__
        │       │   ├───extern
        │       │   │   └───__pycache__
        │       │   ├───_distutils
        │       │   │   ├───command
        │       │   │   │   └───__pycache__
        │       │   │   └───__pycache__
        │       │   ├───_vendor
        │       │   │   ├───importlib_metadata
        │       │   │   │   └───__pycache__
        │       │   │   ├───importlib_resources
        │       │   │   │   └───__pycache__
        │       │   │   ├───jaraco
        │       │   │   │   ├───text
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───more_itertools
        │       │   │   │   └───__pycache__
        │       │   │   ├───packaging
        │       │   │   │   └───__pycache__
        │       │   │   ├───pyparsing
        │       │   │   │   ├───diagram
        │       │   │   │   │   └───__pycache__
        │       │   │   │   └───__pycache__
        │       │   │   ├───tomli
        │       │   │   │   └───__pycache__
        │       │   │   └───__pycache__
        │       │   └───__pycache__
        │       ├───setuptools-65.5.0.dist-info
        │       └───_distutils_hack
        │           └───__pycache__
        └───Scripts```
"
1

There are 1 best solutions below

0
DREU007 On

The $tree doesn't provide necessary information. The django project directory looks like that:

.
├── db.sqlite3
├── hexlet_django_blog  # The project directory
│   ├── article  # The app directory
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── forms.py
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   ├── views.py
│   └── wsgi.py
└── manage.py

In this case aricle app is located in the project hexlet_django_blog folder. The reference name could be changed in apps.py:

# article/apps.py
from django.apps import AppConfig


class ArticleConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'hexlet_django_blog.article'  # << This one

The settings.py contains vaiable INSTALLED_APPS, add the app name in it:

INSTALLED_APPS = [
    ...
    'hexlet_django_blog',  # The project added to be treated as an app
    'hexlet_django_blog.article',  # The app name
]

If the settings.py is missing you could try to create an empty django project and then add necessary infromation from copied project.