Это скелет проекта.Каталог: пользователи.testing.py и models.py находятся в каталоге пользователя.
Для следующего кода генерируется указанная ошибка:
from .models import CustomUser
username='Jason'
userLL = CustomUser.objects.get(username=username)
print(userLL)
last_login = userLL.last_login
print(last_login)
Ошибка:
Traceback (most recent call last):
File "C:/Users/lenovo/Desktop/vidyaConnect/users/testing.py", line 1, in <module>
from .models import CustomUser
ModuleNotFoundError: No module named '__main__.models'; '__main__' is not a package
ЕслиЯ удаляю точку (.) перед моделями, я получаю следующую ошибку
Traceback (most recent call last):
File "C:/Users/lenovo/Desktop/vidyaConnect/users/testing.py", line 1, in <module>
from models import CustomUser
File "C:\Users\lenovo\Desktop\vidyaConnect\users\models.py", line 1, in <module>
from django.contrib.auth.models import AbstractUser
File "C:\Users\lenovo\Desktop\projectVC\venv\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\lenovo\Desktop\projectVC\venv\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\lenovo\Desktop\projectVC\venv\lib\site-packages\django\db\models\base.py", line 103, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Users\lenovo\Desktop\projectVC\venv\lib\site-packages\django\apps\registry.py", line 252, in get_containing_app_config
self.check_apps_ready()
File "C:\Users\lenovo\Desktop\projectVC\venv\lib\site-packages\django\apps\registry.py", line 134, in check_apps_ready
settings.INSTALLED_APPS
File "C:\Users\lenovo\Desktop\projectVC\venv\lib\site-packages\django\conf\__init__.py", line 79, in __getattr__
self._setup(name)
File "C:\Users\lenovo\Desktop\projectVC\venv\lib\site-packages\django\conf\__init__.py", line 64, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.