ImportError:没有名为system_admin的模块

时间:2017-08-21 08:46:25

标签: python django

当我运行服务器时:

$ python manage.py runserver

但是得到了轰鸣声错误:

Unhandled exception in thread started by <function wrapper at 0x1015d0320>
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/utils/autoreload.py", line 250, in raise_last_exception
    six.reraise(*_exception)
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/apps/config.py", line 127, in create
    import_module(entry)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named system_admin

这是我的项目目录:

我的项目(officialWeb)有一个APP(frontend),将来我会创建systemAdminuserAdmin APP。

为什么会出现ImportError: No module named system_admin错误?

修改-1

我项目的settings.py

import os


ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.system_admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'frontend',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'officialWeb.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'officialWeb.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

2 个答案:

答案 0 :(得分:1)

您的问题的原因如下所示。您已安装的应用程序中的行。

'django.contrib.system_admin',

Django的contrib模块中没有名为system_admin的模块。这可以使用

进行验证
In [1]: import django.contrib

In [2]: dir(django.contrib)
Out[2]: 
['__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 'admin',
 'auth',
 'contenttypes',
 'messages',
 'postgres',
 'sessions',
 'sites',
 'staticfiles']

我想您打算在installed_apps

中使用django.contrib.admin

答案 1 :(得分:0)

如果您尚未创建应用,并且已将其包含在settings.py中,那么它将始终崩溃,直到您实际为其提供有效的应用。因此,要修复错误,请转到settings.py查找INSTALLED_APPS,然后注释掉system_adminuser_admin行。然后,当您实际创建它们时,可以取消注释它们。