pythonpython-3.xdjangodjango-models

ModuleNotFoundError: No module named 'mysite' when try to call django-admin


when I run the command django-admin collectstatic in terminal i'm getting the following error:

ModuleNotFoundError: No module named 'mysite'

it even appears at the end of the list django-admin commands help

Type 'django-admin help <subcommand>' for help on a specific subcommand.
Available subcommands:

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    runserver
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver
Note that only Django core commands are listed as settings are not properly configured (error: No module named 'mysite').

The project structure

myProject
    |
    +----mysite
    |        |
    |        +----settings.py
    |        +----wsgi.py
    |        +----urls.py
    |
    |
    +----todo (app)
    |
    +----accounts(app)
    |
    +----myvenv

setting.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
WSGI_APPLICATION = 'mysite.wsgi.application'

wsgi.py

import os
from django.core.wsgi import get_wsgi_application
    
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
application = get_wsgi_application()

Solution

  • instead of django-admin collectstatic use this command

    python manage.py collectstatic
    

    refer to this topic https://docs.djangoproject.com/en/3.1/ref/django-admin/#django-admin-and-manage-py