简体   繁体   English

服务器启动时出现Django异常-找不到模块

[英]Django exception on server start up - module not found

I have searched online for other solutions with little luck. 我很少在网上搜索其他解决方案。 Posting here is a last resort. 张贴在这里是万不得已的方法。

Everything was working well with my Django project. 我的Django项目一切正常。 Then suddenly it stopped running the server as it used to. 然后突然停止了服务器的运行。 I'm not sure at all what I have done wrong. 我完全不确定我做错了什么。

The issue is persistent across all of the git branches (it wasn't like this before) - making it even more confusing as the problem is not isolated to my branch only. 这个问题在所有git分支上都存在(以前不是这样)-使得问题更加混乱,因为问题不仅限于我的分支。

Here is the error traceback: 错误回溯如下:

    WARNINGS:
?: (1_7.W001) MIDDLEWARE_CLASSES is not set.
    HINT: Django 1.7 changed the global defaults for the MIDDLEWARE_CLASSES. django.contrib.sessions.middleware.SessionMiddleware, django.contrib.auth.middleware.AuthenticationMiddleware, and django.contrib.messages.middleware.MessageMiddleware were removed from the defaults. If your project needs these middleware then you should configure this setting.

System check identified 1 issue (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001A7227EB598>
Traceback (most recent call last):
  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\venv\lib\site-packages\django\utils\autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\venv\lib\site-packages\django\core\management\commands\runserver.py", line 116, in inner_run
    self.check_migrations()
  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\venv\lib\site-packages\django\core\management\commands\runserver.py", line 168, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\venv\lib\site-packages\django\db\migrations\executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\venv\lib\site-packages\django\db\migrations\loader.py", line 47, in __init__
    self.build_graph()
  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\venv\lib\site-packages\django\db\migrations\loader.py", line 185, in build_graph
    self.load_disk()
  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\venv\lib\site-packages\django\db\migrations\loader.py", line 103, in load_disk
    migration_module = import_module("%s.%s" % (module_name, migration_name))
  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\venv\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\connect_therapy\migrations\0021_auto_20180313_1946.py", line 4, in <module>
    import django.contrib.auth.base_user
ModuleNotFoundError: No module named 'django.contrib.auth.base_user'

Also, note that I tried changing to MIDDLEWARE_CLASSES [...] in settings.py - but it didnt help. 另外,请注意,我尝试在settings.py中更改为MIDDLEWARE_CLASSES [...]-但这没有帮助。

Here is settings.py: 这是settings.py:

"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.11.7.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'key'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True # should be true unless doing test on local network

ALLOWED_HOSTS = ['*'] # should be [] unless doing test on local network (then it should be ['*']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'co.apps.CTherapyConfig',
    "sslserver", 
]

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 = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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 = 'mysite.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',
    },
]

# This must be changed for production
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# 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

TWILIO_PHONE_NUMBER = '+number'

TWILIO_ACC_SID = 'key'

TWILIO_AUTH_TOKEN = 'token'


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

STATIC_URL = '/static/'

Any ideas/suggestions are welcome. 欢迎任何想法/建议。

Just to reiterate. 只是重申一下。 This came out of the blue. 这是出乎意料的。 No idea what caused it. 不知道是什么原因造成的。

Thank you. 谢谢。

It came out because something changed in your project and a migration now fails. 出来的原因是您的项目中发生了某些更改,并且现在迁移失败。

In the error log you can see 在错误日志中,您可以看到

  File "C:\Users\ASUS\PycharmProjects\5CCS2SEG_Major\connect_therapy\migrations\0021_auto_20180313_1946.py", line 4, in <module>
    import django.contrib.auth.base_user
ModuleNotFoundError: No module named 'django.contrib.auth.base_user'

What that migration does? 那个迁移做什么? Is still valid or the project is changed and the migration try to load resources that are not anymore available? 仍然有效或项目已更改,并且迁移尝试加载不再可用的资源?

If you run python manage.py shell are you able to import from 'django.contrib.auth.base_user'? 如果运行python manage.py shell ,是否可以从“ django.contrib.auth.base_user”导入? The problem seems to be in that migration 问题似乎在于迁移

The 'solution' at the end was to just make a new virtual environment. 最后的“解决方案”只是创建一个新的虚拟环境。 For some reason the old one messed up. 由于某种原因,旧的弄糟了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM