2

I tried to import User model in service.py file in user_app model

from .models import User

Модель User в .models

class User(AbstractUser):
image = models.ImageField(upload_to='profile-image/')
send_massege = models.BooleanField(default=True)

settings.py file:

    import os.path
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-59g7og+h6r2*20t+72f3t++op2lv9(x0z3=+*mzfdms079msf1'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'products.apps.ProductsConfig',
    'user_app.apps.UserAppConfig',
    'social_django',
    'cart',
    'django.contrib.sitemaps',
]

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',
    'social_django.middleware.SocialAuthExceptionMiddleware',
]

ROOT_URLCONF = 'prosite.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',
                'social_django.context_processors.backends'
            ],
        },
    },
]

WSGI_APPLICATION = 'prosite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

AUTHENTICATION_BACKENDS = (
    'social_core.backends.google.GoogleOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)


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/4.0/topics/i18n/

LANGUAGE_CODE = 'ru'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


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

STATIC_URL = 'static/'

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

AUTH_USER_MODEL='user_app.User'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

LOGIN_URL = 'user_app:login'
LOGIN_REDIRECT_URL = 'products:main_page'

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '920464034328-m9g1ptdl0ogf2dks4l456fgbfntll5vn.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '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'

CART_SESSION_ID = 'cart'

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'yonetiofficial@gmail.com'
EMAIL_HOST_PASSWORD = 'zwasrlakvlcwtkfg'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False

CELERY_BROKER_URL = 'redis://127.0.0.1:6379/0'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/0'
CELERY_BROKER_TRANSPORT_OPTIONS = {'visibility_timeout':3600}
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

i got this error

    File "E:\Python\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "E:\Python\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "E:\Python\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "E:\Python\lib\site-packages\django\core\management\commands\runserver.py", line 115, in inner_run
    autoreload.raise_last_exception()
  File "E:\Python\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "E:\Python\lib\site-packages\django\core\management\__init__.py", line 381, in execute
    autoreload.check_errors(django.setup)()
  File "E:\Python\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "E:\Python\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "E:\Python\lib\site-packages\django\apps\registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "E:\Python\lib\site-packages\django\apps\config.py", line 211, in create
    mod = import_module(mod_path)
  File "E:\Python\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 "E:\PyProjects\prosite\user_app\apps.py", line 3, in <module>
    from .tasks import send_activation_notification
  File "E:\PyProjects\prosite\user_app\tasks.py", line 3, in <module>
    from .service import send_an
  File "E:\PyProjects\prosite\user_app\service.py", line 4, in <module>
    from .models import User
  File "E:\PyProjects\prosite\user_app\models.py", line 1, in <module>
    from django.contrib.auth.models import AbstractUser
  File "E:\Python\lib\site-packages\django\contrib\auth\models.py", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "E:\Python\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "E:\Python\lib\site-packages\django\db\models\base.py", line 108, in __new__
    app_config = apps.get_containing_app_config(module)
  File "E:\Python\lib\site-packages\django\apps\registry.py", line 253, in get_containing_app_config
    self.check_apps_ready()
  File "E:\Python\lib\site-packages\django\apps\registry.py", line 136, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

1 Answers1

0

open prosite/wsgi.py file and add these lines :

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'prosite.settings')

application = get_wsgi_application()
monim
  • 3,641
  • 2
  • 10
  • 25
  • I already had all these lines. This only happens when I add (from .models import User) to apps or sevice or tasks files. If I add celery to the project (maybe this explains something) – Vadim Bagriy Oct 05 '22 at 12:21
  • Maybe it's because of selery Check this [answer](https://stackoverflow.com/questions/73933432/django-celery-cannot-import-name-celery-from-celery-after-restart-docker/73934771#73934771) – monim Oct 05 '22 at 14:43