我在网上搜索了其他解决方案但运气不佳。在这里发布是最后的手段。
我的Django项目一切都运行良好。然后突然它像以前一样停止运行服务器。我完全不确定我做错了什么。
这个问题在所有git分支中都是持久的(以前它不是这样的) - 因为问题不是仅仅分离到我的分支而使它更加混乱。
以下是错误追溯:
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'
另外,请注意我尝试在settings.py中更改为MIDDLEWARE_CLASSES [...] - 但它没有帮助。
这是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/'
欢迎任何想法/建议。
重申一下。这突然出现了。不知道是什么造成的。
谢谢。
答案 0 :(得分:0)
它出现了,因为项目中的某些内容发生了变化,现在迁移失败了。
在错误日志中,您可以看到
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'
迁移的作用是什么?仍然有效或项目已更改,迁移是否尝试加载不再可用的资源?
如果您运行python manage.py shell
,您是否可以从'django.contrib.auth.base_user'导入?问题似乎在于迁移
答案 1 :(得分:0)
最后的“解决方案”是创建一个新的虚拟环境。出于某种原因,老人搞砸了。