Zainab Imad
Zainab Imad

Reputation: 29

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()

Upvotes: 2

Views: 2104

Answers (3)

Sam
Sam

Reputation: 262

Change directory into myProject, if not already there:

cd myProject

Set the required environment variables:

export DJANGO_SETTINGS_MODULE=mysite.settings
export PYTHONPATH=$(pwd)

Run django-admin:

django-admin

Upvotes: 0

cizario
cizario

Reputation: 4254

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

Upvotes: 2

Galalen
Galalen

Reputation: 64

Create __init__.py file inside myside dir and myproject

Upvotes: 0

Related Questions