ModuleNotFoundError:尝试调用django-admin时没有名为“ mysite”的模块

时间:2020-11-06 05:37:37

标签: python python-3.x django django-models

当我在终端中运行命令django-admin collectstatic时,出现以下错误:

ModuleNotFoundError: No module named 'mysite'

它甚至出现在列表django-admin命令帮助的结尾

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').

项目结构

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

2 个答案:

答案 0 :(得分:0)

在myside目录和myproject中创建__init__.py文件

答案 1 :(得分:0)

代替django-admin collectstatic使用此命令

python manage.py collectstatic

请参阅本主题https://docs.djangoproject.com/en/3.1/ref/django-admin/#django-admin-and-manage-py