[英]Django / Python : ModuleNotFoundError: No module named 'd'
The project seemed fine till yesterday, but suddenly, when I tried to start the server after some settings changes today, this error pops up everytime:该项目直到昨天看起来还不错,但是突然,当我在今天更改一些设置后尝试启动服务器时,每次都会弹出此错误:
Traceback (most recent call last):
File "/PROJECT/manage.py", line 21, in <module>
main()
File "/PROJECT/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
django.setup()
File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 224, in create
import_module(entry)
File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'd'
the project manage.py file:项目 manage.py 文件:
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PROJECT.settings.production')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
Please help me solve this and please do ask if you need more information.请帮我解决这个问题,如果您需要更多信息,请询问。
Thank you in advance.先感谢您。
EDIT: Add settings编辑:添加设置
settings/base.py设置/base.py
"""Django settings for PROJECT project."""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
INTERNAL_IPS = [
'127.0.0.1',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'django_filters',
'hrm',
'inventory',
'notification',
'production',
'django_celery_beat',
]
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',
'debug_toolbar.middleware.DebugToolbarMiddleware',
]
ROOT_URLCONF = 'MIST_ERP.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [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 = 'MIST_ERP.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
# IN RESPECTIVE SETTINGS FILES
# Password validation
# https://docs.djangoproject.com/en/3.0/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/3.0/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/3.0/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / "static",
]
# STATIC_ROOT = os.path.join(BASE_DIR, "static")
# Media Settings ( Profile photos, Project photos )
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / "media"
# AUTHENTICATION BACKENDS
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.TokenAuthentication",
]
# REST FRAMEWORK CONFIG
REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10,
'PAGINATE_BY': 10,
}
# MEMCACHED
"""
Memcached is an entirely memory-based cache server,
The fastest, most efficient type of cache supported natively by Django,
"""
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'TIMEOUT': None,
'OPTIONS': {
'server_max_value_length': 1024 * 1024 * 2,
}
}
}
# LOGGING
LOG_PATH = BASE_DIR / 'logs'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': f'{LOG_PATH}/debug.log',
},
'file_ldap': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': f'{LOG_PATH}/debug_ldap.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
"django_auth_ldap": {
"level": "DEBUG",
"handlers": ["file_ldap"],
'propagate': True,
}
},
}
# SETTINGS VARS
LOGIN_URL = '/login/'
# DJANGO AUTO FIELD
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
development.py ( currently being used ) development.py(目前正在使用)
from PROJECT.settings.base import *
import os
DEBUG = True
INSTALLED_APPS += 'debug_toolbar'
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
In the deployment.py
, you should wrap the 'debug_toolbar'
string in a collection, for example a list, otherwise you will add one item per character to the INSTALLED_SETTINGS
, and thus then you would load as apps 'd'
, 'e'
, 'b'
, etc.在
deployment.py
中,您应该将'debug_toolbar'
字符串包装在一个集合中,例如一个列表,否则您将为每个字符添加一个项目到INSTALLED_SETTINGS
,因此您将加载为应用程序'd'
, 'e'
, 'b'
等
You thus can rewrite this to:因此,您可以将其重写为:
# deployment.py
# …
INSTALLED_APPS +=
['debug_toolbar']
# …
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.