模型尚未加载/未定义SECRET_KEY

时间:2015-10-19 22:57:06

标签: python django django-models

好的:我正在尝试使用./manage.py makemigrations命令,但得到两个错误之一。

  1. 如果我没有注释掉第三行,我收到的错误是没有定义SECRET_KEY。 django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

  2. 但是,如果我发表评论,我会收到错误django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

  3. 据我所知,我相信MIDDLEWARE_CLASSES可能存在重复,但我找不到它(之前的帖子提到过它)。所以,现在我陷入了这个循环。我省略了什么,还是我复制了什么? (该应用程序用于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",
    ]
    

0 个答案:

没有答案