Django 1.8:django.core.exceptions.AppRegistryNotReady:模型还没有加载

时间:2015-12-06 12:29:49

标签: python django django-models account pinax

我已经阅读了有关此问题的其他问题,但无法解决这个问题。

我在做什么:在我的本地PC上我有Django 1.8.5和几个应用程序,一切正常。到1.8.5我不久前从1.6.10升级了。 但是当我在生产服务器上安装django 1.8.5时,我会遇到类似django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet的错误(下面的完整回溯)。

奇怪,为什么localhost上的相同代码有效?

我的猜测为什么会发生这种情况:正如Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet所指出的那样,它可能是Pinax帐户模块问题https://github.com/pinax/django-user-accounts,但我尝试修复,错误仍然存​​在。

另外,如果我在服务器上重新安装django到1.6.10它可以工作,甚至可以为用户注册和授权!请帮助解决如何修复Django 1.8.5上的错误。

我附上了settings.py:

    # -*- coding: utf-8 -*-
# Django settings for engine project.
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ALLOWED_HOSTS = ['engine.domain.com']

ADMINS = (
    ('Joomler', 'team@domain.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'gdb',                      # Or path to database file if using sqlite3.
        'USER': 'postgres',                      # Not used with sqlite3.
        'PASSWORD': '111111',                  # Not used with sqlite3.
        'HOST': 'localhost',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
 }

TIME_ZONE = 'Europe/Moscow'

LANGUAGE_CODE = 'ru-ru'

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

USE_I18N = True

USE_L10N = True

MEDIA_ROOT = os.path.join(PROJECT_ROOT, '..', 'media')

MEDIA_URL = '/media/'

STATIC_ROOT = os.path.join(PROJECT_ROOT, '..', 'static')

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
DOMAIN_URL = '/post/'

# Additional locations of static files
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
    #'djangobower.finders.BowerFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'cr@-7=ymmhr68y6xjhb#h$!y054baa(h)8e$q0t+oizv&e0o)j'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
    "account.middleware.LocaleMiddleware",
    "account.middleware.TimezoneMiddleware",    
)

CRISPY_TEMPLATE_PACK = 'bootstrap3'

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP

TEMPLATE_CONTEXT_PROCESSORS = TCP + (
    'django.core.context_processors.request',
    'django.core.context_processors.csrf',
    "account.context_processors.account",
)

ROOT_URLCONF = 'engine.urls'

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

TEMPLATE_DIRS = (
    #os.path.join(PROJECT_ROOT, 'templates'),
        # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(PROJECT_PATH, '..', 'templates'),
    os.path.join(PROJECT_PATH, '..', 'article', 'templates'),
    os.path.join(PROJECT_PATH, '..', 'loginsys', 'templates'),
    os.path.join(PROJECT_PATH, '..', 'books', 'templates'),
    os.path.join(PROJECT_PATH, '..', 'booksin', 'templates'),
    os.path.join(PROJECT_PATH, '..', 'vkontakte_groups', 'templates'),
    os.path.join(PROJECT_PATH, '..', 'vk_wall', 'templates'),
    os.path.join(PROJECT_PATH, '..', 'registration', 'templates'),
    os.path.join(PROJECT_PATH, '..', 'account', 'templates'),
)

INSTALLED_APPS = (
    'suit',
    'crispy_forms',
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_countries',
    #'debug_toolbar',
    'article',
    #'loginsys', #commented because use registration and django-profile
    #'registration',
    #'userprofile',  #https://github.com/alekam/django-profile/blob/master/INSTALL.txt
    #'demoprofile',
    #'south',  #removed in django 1.8
    #'books',
    #'booksin',
    'contact',
    'vk_wall',

    # theme
    "bootstrapform",
    "pinax_theme_bootstrap",

    # external
    "account",
    "metron",
    "pinax.eventlog",

    # 'oauth_tokens',
    # 'taggit',
    # 'vkontakte_api',
    # 'vkontakte_places',
    # 'vkontakte_users',
    # 'vkontakte_groups',
    # 'vkontakte_wall',
    # 'vkontakte_board',
    # 'm2m_history',

    #'tastypie',
    #'rest_framework',

    #'blog',
    #'regme',
    #'django_nvd3',
    #'djangobower',
    #'demoproject',
)

# Site information (domain and name) for use in activation mail messages
SITE = {'domain': 'site.domain.com', 'name': 'site'}

#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# A sample logging configuration. The only tangible logging
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,
        },
    }
}


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = 'aaaaaaaaaaaa@gmail.com'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'aaaaaaaaaaaa@gmail.com'
EMAIL_HOST_PASSWORD = '11111111111'
EMAIL_PORT = 587


ACCOUNT_OPEN_SIGNUP = True
ACCOUNT_EMAIL_UNIQUE = True
ACCOUNT_EMAIL_CONFIRMATION_REQUIRED = False
ACCOUNT_LOGIN_REDIRECT_URL = "/vk/projects/" # "/settings/"
ACCOUNT_LOGOUT_REDIRECT_URL = "/"
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 2
ACCOUNT_USE_AUTH_AUTHENTICATE = True

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

以下是服务器错误日志的完整回溯:

    [Sun Dec 06 15:00:00.097892 2015] [:error] [pid 20184:tid 140014929971072] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Sun Dec 06 15:00:00.097973 2015] [:error] [pid 20184:tid 140014929971072] Traceback (most recent call last):
[Sun Dec 06 15:00:00.098003 2015] [:error] [pid 20184:tid 140014929971072]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Sun Dec 06 15:00:00.099232 2015] [:error] [pid 20184:tid 140014929971072]     assert tlock is not None
[Sun Dec 06 15:00:00.099279 2015] [:error] [pid 20184:tid 140014929971072] AssertionError: 
[Sun Dec 06 15:00:00.121192 2015] [:error] [pid 20183:tid 140014929971072] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Sun Dec 06 15:00:00.121320 2015] [:error] [pid 20183:tid 140014929971072] Traceback (most recent call last):
[Sun Dec 06 15:00:00.121355 2015] [:error] [pid 20183:tid 140014929971072]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Sun Dec 06 15:00:00.122557 2015] [:error] [pid 20183:tid 140014929971072]     assert tlock is not None
[Sun Dec 06 15:00:00.122599 2015] [:error] [pid 20183:tid 140014929971072] AssertionError: 
[Sun Dec 06 15:00:00.181301 2015] [:error] [pid 20184:tid 140014929971072] Exception ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
[Sun Dec 06 15:00:00.181371 2015] [:error] [pid 20184:tid 140014929971072] Traceback (most recent call last):
[Sun Dec 06 15:00:00.181402 2015] [:error] [pid 20184:tid 140014929971072]   File "/usr/lib/python3.4/threading.py", line 1288, in _shutdown
[Sun Dec 06 15:00:00.182642 2015] [:error] [pid 20184:tid 140014929971072]     assert tlock is not None
[Sun Dec 06 15:00:00.182712 2015] [:error] [pid 20184:tid 140014929971072] AssertionError: 
[Sun Dec 06 15:00:00.438789 2015] [mpm_event:notice] [pid 20180:tid 140014929971072] AH00491: caught SIGTERM, shutting down
[Sun Dec 06 15:00:01.196734 2015] [:warn] [pid 20557:tid 139670936528768] mod_wsgi: Compiled for Python/3.4.0.
[Sun Dec 06 15:00:01.196827 2015] [:warn] [pid 20557:tid 139670936528768] mod_wsgi: Runtime using Python/3.4.3.
[Sun Dec 06 15:00:01.197563 2015] [mpm_event:notice] [pid 20557:tid 139670936528768] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/3.4.3 configured -- resuming normal operations
[Sun Dec 06 15:00:01.197591 2015] [core:notice] [pid 20557:tid 139670936528768] AH00094: Command line: '/usr/sbin/apache2'
[Sun Dec 06 15:00:09.294007 2015] [:error] [pid 20561:tid 139670650316544] Internal Server Error: /vk/projects/
[Sun Dec 06 15:00:09.294064 2015] [:error] [pid 20561:tid 139670650316544] Traceback (most recent call last):
[Sun Dec 06 15:00:09.294070 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 108, in get_response
[Sun Dec 06 15:00:09.294076 2015] [:error] [pid 20561:tid 139670650316544]     response = middleware_method(request)
[Sun Dec 06 15:00:09.294114 2015] [:error] [pid 20561:tid 139670650316544]   File "/var/www/engine/account/middleware.py", line 29, in process_request
[Sun Dec 06 15:00:09.294120 2015] [:error] [pid 20561:tid 139670650316544]     translation.activate(self.get_language_for_user(request))
[Sun Dec 06 15:00:09.294125 2015] [:error] [pid 20561:tid 139670650316544]   File "/var/www/engine/account/middleware.py", line 20, in get_language_for_user
[Sun Dec 06 15:00:09.294130 2015] [:error] [pid 20561:tid 139670650316544]     if request.user.is_authenticated():
[Sun Dec 06 15:00:09.294135 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/utils/functional.py", line 225, in inner
[Sun Dec 06 15:00:09.294141 2015] [:error] [pid 20561:tid 139670650316544]     self._setup()
[Sun Dec 06 15:00:09.294145 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/utils/functional.py", line 365, in _setup
[Sun Dec 06 15:00:09.294150 2015] [:error] [pid 20561:tid 139670650316544]     self._wrapped = self._setupfunc()
[Sun Dec 06 15:00:09.294155 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/middleware.py", line 22, in <lambda>
[Sun Dec 06 15:00:09.294160 2015] [:error] [pid 20561:tid 139670650316544]     request.user = SimpleLazyObject(lambda: get_user(request))
[Sun Dec 06 15:00:09.294176 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/middleware.py", line 10, in get_user
[Sun Dec 06 15:00:09.294182 2015] [:error] [pid 20561:tid 139670650316544]     request._cached_user = auth.get_user(request)
[Sun Dec 06 15:00:09.294187 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 167, in get_user
[Sun Dec 06 15:00:09.294192 2015] [:error] [pid 20561:tid 139670650316544]     user_id = _get_user_session_key(request)
[Sun Dec 06 15:00:09.294196 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 59, in _get_user_session_key
[Sun Dec 06 15:00:09.294201 2015] [:error] [pid 20561:tid 139670650316544]     return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
[Sun Dec 06 15:00:09.294206 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 150, in get_user_model
[Sun Dec 06 15:00:09.294210 2015] [:error] [pid 20561:tid 139670650316544]     return django_apps.get_model(settings.AUTH_USER_MODEL)
[Sun Dec 06 15:00:09.294215 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 199, in get_model
[Sun Dec 06 15:00:09.294236 2015] [:error] [pid 20561:tid 139670650316544]     self.check_models_ready()
[Sun Dec 06 15:00:09.294241 2015] [:error] [pid 20561:tid 139670650316544]   File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 131, in check_models_ready
[Sun Dec 06 15:00:09.294246 2015] [:error] [pid 20561:tid 139670650316544]     raise AppRegistryNotReady("Models aren't loaded yet.")
[Sun Dec 06 15:00:09.294253 2015] [:error] [pid 20561:tid 139670650316544] django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
[Sun Dec 06 15:00:09.294263 2015] [:error] [pid 20561:tid 139670650316544] 
[Sun Dec 06 15:00:09.321835 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192] mod_wsgi (pid=20561): Exception occurred processing WSGI script '/usr/django/engine.wsgi'.
[Sun Dec 06 15:00:09.321920 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192] Traceback (most recent call last):
[Sun Dec 06 15:00:09.321989 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 108, in get_response
[Sun Dec 06 15:00:09.321998 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     response = middleware_method(request)
[Sun Dec 06 15:00:09.322033 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/var/www/engine/account/middleware.py", line 29, in process_request
[Sun Dec 06 15:00:09.322042 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     translation.activate(self.get_language_for_user(request))
[Sun Dec 06 15:00:09.322073 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/var/www/engine/account/middleware.py", line 20, in get_language_for_user
[Sun Dec 06 15:00:09.322110 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     if request.user.is_authenticated():
[Sun Dec 06 15:00:09.322153 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/utils/functional.py", line 225, in inner
[Sun Dec 06 15:00:09.322162 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     self._setup()
[Sun Dec 06 15:00:09.322217 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/utils/functional.py", line 365, in _setup
[Sun Dec 06 15:00:09.322226 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     self._wrapped = self._setupfunc()
[Sun Dec 06 15:00:09.322261 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/middleware.py", line 22, in <lambda>
[Sun Dec 06 15:00:09.322269 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     request.user = SimpleLazyObject(lambda: get_user(request))
[Sun Dec 06 15:00:09.322300 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/middleware.py", line 10, in get_user
[Sun Dec 06 15:00:09.322308 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     request._cached_user = auth.get_user(request)
[Sun Dec 06 15:00:09.322339 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 167, in get_user
[Sun Dec 06 15:00:09.322347 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     user_id = _get_user_session_key(request)
[Sun Dec 06 15:00:09.322379 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 59, in _get_user_session_key
[Sun Dec 06 15:00:09.322387 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
[Sun Dec 06 15:00:09.322436 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 150, in get_user_model
[Sun Dec 06 15:00:09.322445 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     return django_apps.get_model(settings.AUTH_USER_MODEL)
[Sun Dec 06 15:00:09.322477 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 199, in get_model
[Sun Dec 06 15:00:09.322485 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     self.check_models_ready()
[Sun Dec 06 15:00:09.322515 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 131, in check_models_ready
[Sun Dec 06 15:00:09.322523 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     raise AppRegistryNotReady("Models aren't loaded yet.")
[Sun Dec 06 15:00:09.322551 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192] django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
[Sun Dec 06 15:00:09.322569 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192] 
[Sun Dec 06 15:00:09.322575 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192] During handling of the above exception, another exception occurred:
[Sun Dec 06 15:00:09.322580 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192] 
[Sun Dec 06 15:00:09.322593 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192] Traceback (most recent call last):
[Sun Dec 06 15:00:09.322810 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/wsgi.py", line 189, in __call__
[Sun Dec 06 15:00:09.322820 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     response = self.get_response(request)
[Sun Dec 06 15:00:09.322858 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 218, in get_response
[Sun Dec 06 15:00:09.322867 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Sun Dec 06 15:00:09.322899 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 261, in handle_uncaught_exception
[Sun Dec 06 15:00:09.322908 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     return debug.technical_500_response(request, *exc_info)
[Sun Dec 06 15:00:09.323343 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 97, in technical_500_response
[Sun Dec 06 15:00:09.323355 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     html = reporter.get_traceback_html()
[Sun Dec 06 15:00:09.323391 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 383, in get_traceback_html
[Sun Dec 06 15:00:09.323399 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     c = Context(self.get_traceback_data(), use_l10n=False)
[Sun Dec 06 15:00:09.323430 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 328, in get_traceback_data
[Sun Dec 06 15:00:09.323438 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     frames = self.get_traceback_frames()
[Sun Dec 06 15:00:09.323468 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 501, in get_traceback_frames
[Sun Dec 06 15:00:09.323484 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     'vars': self.filter.get_traceback_frame_variables(self.request, tb.tb_frame),
[Sun Dec 06 15:00:09.323521 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 234, in get_traceback_frame_variables
[Sun Dec 06 15:00:09.323530 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     cleansed[name] = self.cleanse_special_types(request, value)
[Sun Dec 06 15:00:09.323560 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/views/debug.py", line 189, in cleanse_special_types
[Sun Dec 06 15:00:09.323568 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     if isinstance(value, HttpRequest):
[Sun Dec 06 15:00:09.323599 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/utils/functional.py", line 225, in inner
[Sun Dec 06 15:00:09.323607 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     self._setup()
[Sun Dec 06 15:00:09.323637 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/utils/functional.py", line 365, in _setup
[Sun Dec 06 15:00:09.323645 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     self._wrapped = self._setupfunc()
[Sun Dec 06 15:00:09.323675 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/middleware.py", line 22, in <lambda>
[Sun Dec 06 15:00:09.323683 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     request.user = SimpleLazyObject(lambda: get_user(request))
[Sun Dec 06 15:00:09.323713 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/middleware.py", line 10, in get_user
[Sun Dec 06 15:00:09.323721 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     request._cached_user = auth.get_user(request)
[Sun Dec 06 15:00:09.323751 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 167, in get_user
[Sun Dec 06 15:00:09.323758 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     user_id = _get_user_session_key(request)
[Sun Dec 06 15:00:09.323787 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 59, in _get_user_session_key
[Sun Dec 06 15:00:09.323795 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
[Sun Dec 06 15:00:09.323825 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/__init__.py", line 150, in get_user_model
[Sun Dec 06 15:00:09.323833 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     return django_apps.get_model(settings.AUTH_USER_MODEL)
[Sun Dec 06 15:00:09.323863 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 199, in get_model
[Sun Dec 06 15:00:09.323870 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     self.check_models_ready()
[Sun Dec 06 15:00:09.323899 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]   File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 131, in check_models_ready
[Sun Dec 06 15:00:09.323915 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192]     raise AppRegistryNotReady("Models aren't loaded yet.")
[Sun Dec 06 15:00:09.323940 2015] [:error] [pid 20561:tid 139670650316544] [client 87.117.12.160:5192] django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

编辑: 我有应用帐户Pinax帐户模块问题https://github.com/pinax/django-user-accounts,在该应用中有几个地方有&#39; get_user_model&#39;: views.py:

def create_user(self, form, commit=True, **kwargs):
    **user = get_user_model()**(**kwargs)
    username = form.cleaned_data.get("username")
    if username is None:
        username = self.generate_username(form)
    user.username = username
    user.email = form.cleaned_data["email"].strip()
    password = form.cleaned_data.get("password")
    if password:
        user.set_password(password)
    else:
        user.set_unusable_password()
    if commit:
        user.save()
    return user

以及更多:

    def send_email(self, email):
    User = get_user_model()
    protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http")
    current_site = get_current_site(self.request)
    email_qs = EmailAddress.objects.filter(email__iexact=email)
    for user in User.objects.filter(pk__in=email_qs.values("user")):
        uid = int_to_base36(user.id)
        token = self.make_token(user)
        password_reset_url = "{0}://{1}{2}".format(
            protocol,
            current_site.domain,
            reverse("account_password_reset_token", kwargs=dict(uidb36=uid, token=token))
        )
        ctx = {
            "user": user,
            "current_site": current_site,
            "password_reset_url": password_reset_url,
        }
        hookset.send_password_reset_email([user.email], ctx)

和第3名:

    def get_user(self):
    try:
        uid_int = base36_to_int(self.kwargs["uidb36"])
    except ValueError:
        raise Http404()
    return get_object_or_404(get_user_model(), id=uid_int)

2 个答案:

答案 0 :(得分:0)

首先尝试升级到Django 1.7。并检查弃用警告。你很快就会找到有罪的模块。

答案 1 :(得分:0)

简而言之:在位于/usr/django/engine.wsgi的Ubuntu服务器上更改wsgi.py文件(其中engine是您的项目名称)

问题出在文件 wsgi.py 的设置中:设置属于django 1.6版本,但不适用于1.8

我在Stackoverflow上看到了很多答案如何解决,但这对我没有帮助,因为我编辑了位于项目文件夹中的 wsgi.py ,但这是错误的