尚未加载模型/未定义密钥

2024-04-25 22:53:20 发布

您现在位置:Python中文网/ 问答频道 /正文

好的:我试图使用./manage.py makemigrations命令,但是得到两个错误中的任何一个。在

  1. 如果我不注释掉第三行,就会得到一个错误,即没有定义密钥。django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

  2. 但是,如果我注释掉它,我得到的错误是django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

到目前为止,我认为中间件类中可能存在重复,但我找不到它(之前的一篇文章提到过)。所以,现在我被困在这个圈子里了。我是遗漏了什么,还是重复了什么?(这个应用程序是为uni项目设计的,叫做“chitchatapp”)。 谨致问候

import os
import posixpath

#from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = 'chitchatapp.settings'
application = "chitchatapp.wsgi.application"

SECRET_KEY = "pi=!j5^gdg-w3*sm=#yi)3!#5$j*d$zof=5bj-e7rv$$0p#86t"


PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
BASE_DIR = PACKAGE_ROOT

DEBUG = True

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": "dev.db",
    }
}

ALLOWED_HOSTS = []

TIME_ZONE = "UTC"

LANGUAGE_CODE = "en-us"

SITE_ID = int(os.environ.get("SITE_ID", 1))

#########################################################################################

USE_I18N = True

USE_L10N = True

USE_TZ = True

#########################################################################################

MEDIA_ROOT = os.path.join(PACKAGE_ROOT, "site_media", "media")

MEDIA_URL = "/site_media/media/"

#########################################################################################

STATIC_ROOT = os.path.join(PACKAGE_ROOT, "site_media", "static")

STATIC_URL = "/site_media/static/"

STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, "static", "dist"),
]

STATICFILES_FINDERS = [
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "staticfiles.finders.LegacyAppDirectoriesFinder",
    "compressor.finders.CompressorFinder",
]

#########################################################################################

SECRET_KEY = "pi=!j5^gdg-w3*sm=#yi)3!#5$j*d$zof=5bj-e7rv$$0p#86t"

#########################################################################################

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [
            os.path.join(PACKAGE_ROOT, "templates"),
        ],
        "APP_DIRS": True,
        "OPTIONS": {
            "debug": DEBUG,
            "context_processors": [
                "django.contrib.auth.context_processors.auth",
                "django.core.context_processors.debug",
                "django.core.context_processors.i18n",
                "django.core.context_processors.media",
                "django.core.context_processors.static",
                "django.core.context_processors.tz",
                "django.core.context_processors.request",
                "django.contrib.messages.context_processors.messages",
                "account.context_processors.account",
                "pinax_theme_bootstrap.context_processors.theme",
            ],
        },
    },
]

TEMPLATE_LOADERS = [
    "django.template.loaders.filesystem.Loader",
    "django.template.loaders.app_directories.Loader",
]

TEMPLATE_CONTEXT_PROCESSORS = [
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request",
    "django.contrib.messages.context_processors.messages",

    "staticfiles.context_processors.static",

    "pinax.core.context_processors.pinax_settings",

    "pinax.apps.account.context_processors.account",

    "notification.context_processors.notification",
    "announcements.context_processors.site_wide_announcements",
]

#########################################################################################

MIDDLEWARE_CLASSES = [
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.auth.middleware.SessionAuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
    #Postman Demo,
    "django_openid.consumer.SessionConsumer",
    "pinax.apps.account.middleware.LocaleMiddleware",
    "pagination.middleware.PaginationMiddleware",
    "pinax.middleware.security.HideSensistiveFieldsMiddleware",
    "debug_toolbar.middleware.DebugToolbarMiddleware",
]

#########################################################################################

ROOT_URLCONF = "chitchatapp.urls"

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = "chitchatapp.wsgi.application"

INSTALLED_APPS = [
    'django_admin_bootstrapped',
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",  
    "django.contrib.messages",
    "django.contrib.sessions",
    "django.contrib.sites",
    #"django.contrib.staticfiles",

    "django.contrib.humanize",
    "pinax.templatetags",

    # theme
    "bootstrapform",
    "pinax_theme_bootstrap",

    # external
    "notification", # must be first
    "django.contrib.staticfiles",
    "compressor",
    "debug_toolbar",
    "mailer",
    "django_openid",
    "timezones",
    "emailconfirmation",
    "announcements",
    "pagination",
    "idios",
    "metron",

    # Pinax
    "pinax.apps.account",
    "pinax.apps.signup_codes",

    # project
    # "about",
    "profiles",
    'postman',
    "chitchatapp",
]

#########################################################################################

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "filters": {
        "require_debug_false": {
            "()": "django.utils.log.RequireDebugFalse"
        }
    },
    "handlers": {
        "mail_admins": {
            "level": "ERROR",
            "filters": ["require_debug_false"],
            "class": "django.utils.log.AdminEmailHandler"
        }
    },
    "loggers": {
        "django.request": {
            "handlers": ["mail_admins"],
            "level": "ERROR",
            "propagate": True,
        },
    }
}

#########################################################################################

FIXTURE_DIRS = [
    os.path.join(PROJECT_ROOT, "fixtures"),
]

MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

ACCOUNT_OPEN_SIGNUP = True
ACCOUNT_EMAIL_UNIQUE = True
ACCOUNT_EMAIL_CONFIRMATION_REQUIRED = False
ACCOUNT_LOGIN_REDIRECT_URL = "home"
ACCOUNT_LOGOUT_REDIRECT_URL = "home"
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 2
ACCOUNT_USE_AUTH_AUTHENTICATE = True

AUTHENTICATION_BACKENDS = [
    "account.auth_backends.UsernameAuthenticationBackend",
]

Tags: pathdjangocoredebugauthtrueoscontext