Django.core.exceptions.ImproperlyConfigured: WSGI application 'vkbot.wsgi.application' could not be loaded; Error importing module
При запуске сервера python manage.py runserver выдает ошибку:
Performing system checks...
System check identified no issues (0 silenced).
January 13, 2023 - 15:04:26
Django version 4.1.4, using settings 'vkbot.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\module_loading.py", line 30, in import_string
return cached_import(module_path, class_name)
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\module_loading.py", line 15, in cached_import
module = import_module(module_path)
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\Максимка\Desktop\Projects\Python\Bots\BibikaBot\vkbot\wsgi.py", line 8, in <module>
dotenv.read_dotenv(os.path.join(BASE_DIR, ".env"))
AttributeError: module 'dotenv' has no attribute 'read_dotenv'. Did you mean: 'load_dotenv'?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\servers\basehttp.py", line 47, in get_internal_wsgi_application
return import_string(app_path)
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\module_loading.py", line 32, in import_string
raise ImportError(
ImportError: Module "vkbot.wsgi" does not define a "application" attribute/class
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\commands\runserver.py", line 157, in inner_run
handler = self.get_handler(*args, **options)
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py",
line 31, in get_handler
handler = super().get_handler(*args, **options)
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\commands\runserver.py", line 78, in get_handler
return get_internal_wsgi_application()
File "C:\Users\Максимка\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\servers\basehttp.py", line 49, in get_internal_wsgi_application
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application 'vkbot.wsgi.application' could not be loaded; Error importing module.
settings.py:
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'm&!s@8am7b!@e(pl6qt7(os^bqje9-bqhmk()yokj*hr2s-!5a'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['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',
'app',
]
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 = 'vkbot.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 = 'vkbot.wsgi.application'
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
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',
},
]
LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = False
USE_L10N = False
USE_TZ = False
STATIC_URL = '/static/'
BOT_NAME = os.environ['BOT_NAME']
GROUP_ID = os.environ["GROUP_ID"]
BOT_TOKEN = os.environ["GROUP_TOKEN"]
USER_TOKEN = os.environ["USER_TOKEN"]
попробуй так:
WSGI_APPLICATION = 'Vkbot.wsgi.application'