python - 官方 Django 教程第 1 部分 : RuntimeError: maximum recursion depth exceeded in cmp

标签 python django

根据 django 教程,我创建了项目并执行了manage.py runserver,如教程中所述,并且我收到错误“RuntimeError:cmp 中超出了最大递归深度”

有什么办法可以纠正这个问题吗?

我收到此错误:

Validating models...

Unhandled exception in thread started by >
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 92, in inner_run
    self.validate(display_num_errors=True)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 280, in validate
    num_errors = get_validation_errors(s, app)
  File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 166, in get_app_errors
    self._populate()
  File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 72, in _populate
    self.load_app(app_name, True)
  File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 96, in load_app
    models = import_module('.models', app_name)
  File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Python/2.7/site-packages/django/contrib/auth/models.py", line 370, in 
    class AbstractUser(AbstractBaseUser, PermissionsMixin):
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 213, in __new__
    new_class.add_to_class(field.name, copy.deepcopy(field))
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 265, in add_to_class
    value.contribute_to_class(cls, name)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 257, in contribute_to_class
    cls._meta.add_field(self)
  File "/Library/Python/2.7/site-packages/django/db/models/options.py", line 179, in add_field
    self.local_fields.insert(bisect(self.local_fields, field), field)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in 
    '__lt__': [('__gt__', lambda self, other: other 
    '__lt__': [('__gt__', lambda self, other: other 
    '__lt__': [('__gt__', lambda self, other: other 
    '__lt__': [('__gt__', lambda self, other: other .........................
RuntimeError: maximum recursion depth exceeded in cmp

Settings.py

DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
    # ('Your Name', '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aad3c5dfd8f5cfc7cbc3c6eacfd2cbc7dac6cf84c9c5c7" rel="noreferrer noopener nofollow">[email protected]</a>'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}


ALLOWED_HOSTS = []


TIME_ZONE = 'America/Chicago'


LANGUAGE_CODE = 'en-us'

SITE_ID = 1


USE_I18N = True


USE_L10N = True
USE_TZ = True
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)


STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

SECRET_KEY = '+8nn@%#%d8r4##x*t==ja=kbm(514bng1m47yesv1wlsu#%)h4'

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',
)

ROOT_URLCONF = 'mysite.urls'

WSGI_APPLICATION = 'mysite.wsgi.application'

TEMPLATE_DIRS = (
    # 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.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)


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,
        },
    }
}

urls.py

from django.conf.urls import patterns, include, url
home', name='home'),
    # url(r'^mysite/', include('mysite.foo.urls')),
    enter code here
    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
)

最佳答案

我知道这是一个老问题,但我刚刚遇到了同样的错误。将 Python 更新到 v 2.7.5 对我来说很有效。

当我切换帐户但尝试启动同一个 Django 项目时遇到错误,并且我只更新了第一个帐户上的 Python 版本。

关于python - 官方 Django 教程第 1 部分 : RuntimeError: maximum recursion depth exceeded in cmp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15555648/

相关文章:

python - 访问 Johnny 缓存数据

django - 在 Django 中有几个名字和一个主要名字的模型人?

java - Jmeter 没有获得我的 csv 文件中正确的行数

python - 将字符串数组转换为 numpy 数组

带有 OpenSSL v1 的 Python 3.5 MACOS Mojave

django - 如何加载 ClearableFileInput/FileField 的初始值(在绑定(bind)表单之前)

python - 我的 celery redis 任务在 heroku 服务器上的 django 应用程序中不起作用

python - 如何在 django_admin_log 中启用 django rest api CRUD 操作的日志记录?

python - 使用 Pandas 确定最佳组配置

python - 如何使用 Sqlite3 使用列表中的值更新整个列