Django RuntimeError:超出最大递归深度 [英] Django RuntimeError: maximum recursion depth exceeded
问题描述
验证模型...
RuntimeError:最大递归深度超过
我还尝试在manage.py中添加以下行,但没有用。
sys.setrecursionlimit(2000)
部分堆栈跟踪。
由< bound方法启动的线程中未处理的异常< django.contrib.staticfiles的Command.inner_run。 management.commands.runserver.Command对象在0x10e2 *****>>
追溯(最近的最后一次调用):
文件/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/core/management/commands/runserver.py ,line 92,in inner_run
self.validate(display_num_errors = True)
文件/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/core/ management / base.py,第280行验证
num_errors = get_validation_errors(s,app)
文件/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg /django/core/management/validation.py,第35行,get_validation_errors
for(app_name,error)in get_app_errors()。items():
文件/Library/Python/2.7/site -packages / Django-1.5-py2.7.egg / django / db / models / loading.py,第166行,get_app_errors
self._populate()
文件/Library/Python/2.7 /site-packages/Django-1.5-py2.7.egg/django/db/models/loading.py,第72行,在_populate
self.load_app(app_name,True)
文件/ Library / Python / 2.7 / site-packages / Django-1.5-py2.7.egg / django / db / models / loading.py,第96行,在load_app
models = import_module('。models',app_name)
文件/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/utils/importlib.py,第35行,import_module
__import __(name)
文件/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/contrib/auth/models.py ,< module>中的行370
class AbstractUser(AbstractBaseUser,PermissionsMixin):
文件/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/base.py,第213行,__new__
new_class.add_to_class(field.name,copy.deepcopy(field))
文件/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg /django/db/models/base.py,第265行,add_to_class
value.contribute_to_class(cls,name)
文件/Library/Python/2.7/site-packages/Django-1.5- py2.7.egg / django / db / models / fields / __ init__.py,第257行,在contribut_to_class
cls._meta.add_field(self)
文件/Library/Python/2.7/site -packages / Django-1.5-py2.7.egg / django / db / models / options.py,第179行,add_field
self.local_fields.insert(bisect(self.local_fields,field),field)
文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py,第56行,< lambda>
'__lt__':[('__gt__',lambda self,other:other< self),
File/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2。 7 / functools.py,第56行,< lambda>
'__lt__':[('__gt__',lambda self,other:other< self),
File/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2。 7 / functools.py,第56行,< lambda>
'__lt__':[('__gt__',lambda self,other:other< self),
File/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2。 7 / functools.py,第56行,< lambda>
'__lt__':[('__gt__',lambda self,other:other< self),
$ b $我做错了什么?
问题在于functools.py文件。这个文件来自Python。
要解决这个问题,请将此代码(关于python\Lib\fuctools.py中的第56行):
convert = {
pre>
'__lt__':[('__gt__',lambda self,other:other< self),
'__le__',lambda self,other:not other< self),
('__ge__',lambda self,other:not self< other)],
'__le__':[('__ge__ ',lambda self,other:other< = self),
('__lt__',lambda self,other:not other< = self),
('__gt__',lambda self,other:不自我< = other)],
'__gt__':[('__lt__',lambda self,other:other> self),
('__ge__',lambda self,other:not other > self),
('__le__',lambda self,other:not self> other)],
'__ge__':[('__le__',lambda self,other:other> = self),
('__gt__',lambda self,oth呃:不是其他> = self),
('__lt__',lambda self,other:not self> = other)]
}
:
convert = {
'__lt__':[('__gt__',lambda self,other:not(self<另一个或另一个),
('__le__',lambda self,other:self< other或self == other),
('__ge__',lambda self,other:not self < other)],
'__le__':[('__ge__',lambda self,other:not self< = other或self == other),
('__lt__'其他:self< = other而不是self == other),
('__gt__',lambda self,other:not self< = other)],
'__gt__':[('__lt__ ',lambda self,other:not(self> other or self == other)),
('__ge__',lambda self,other:self> other或self == other),
('__le__',lambda self,other:not self> other)],
'__ge__':[('__le__',lambda self,other:(not self> = other)或self == other ),
('__gt__',lambda self,other:self> = other而不是self == other),
('__lt__',lambda self,other:not self> ; =其他)]
}
另请阅读: http://regebro.wordpress.com/2010/12/13/ python-implementation-rich-comparison-the-correct-way /
I'm new to Django. I installed Django using easy_install (on a Mac) and PyDev Django plugin for eclipse. I followed standard procedures to create a new PyDev Django project. When I try to run the project as PyDev: Django, I get the following error.
Validating models... RuntimeError: maximum recursion depth exceeded
I also tried adding the following line in manage.py, but it's of no use.
sys.setrecursionlimit(2000)
Here's the partial stacktrace.
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10e2*****>> Traceback (most recent call last): File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/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-1.5-py2.7.egg/django/core/management/base.py", line 280, in validate num_errors = get_validation_errors(s, app) File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/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-1.5-py2.7.egg/django/db/models/loading.py", line 166, in get_app_errors self._populate() File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/loading.py", line 72, in _populate self.load_app(app_name, True) File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/db/models/loading.py", line 96, in load_app models = import_module('.models', app_name) File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/utils/importlib.py", line 35, in import_module __import__(name) File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/django/contrib/auth/models.py", line 370, in <module> class AbstractUser(AbstractBaseUser, PermissionsMixin): File "/Library/Python/2.7/site-packages/Django-1.5-py2.7.egg/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-1.5-py2.7.egg/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-1.5-py2.7.egg/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-1.5-py2.7.egg/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 <lambda> '__lt__': [('__gt__', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> '__lt__': [('__gt__', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> '__lt__': [('__gt__', lambda self, other: other < self), File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/functools.py", line 56, in <lambda> '__lt__': [('__gt__', lambda self, other: other < self),
What am I doing wrong?
解决方案The problem is in functools.py file. This file is from Python.
To fix the problem replace this (about line 56 in python\Lib\fuctools.py):
convert = { '__lt__': [('__gt__', lambda self, other: other < self), ('__le__', lambda self, other: not other < self), ('__ge__', lambda self, other: not self < other)], '__le__': [('__ge__', lambda self, other: other <= self), ('__lt__', lambda self, other: not other <= self), ('__gt__', lambda self, other: not self <= other)], '__gt__': [('__lt__', lambda self, other: other > self), ('__ge__', lambda self, other: not other > self), ('__le__', lambda self, other: not self > other)], '__ge__': [('__le__', lambda self, other: other >= self), ('__gt__', lambda self, other: not other >= self), ('__lt__', lambda self, other: not self >= other)] }
to that:
convert = { '__lt__': [('__gt__', lambda self, other: not (self < other or self == other)), ('__le__', lambda self, other: self < other or self == other), ('__ge__', lambda self, other: not self < other)], '__le__': [('__ge__', lambda self, other: not self <= other or self == other), ('__lt__', lambda self, other: self <= other and not self == other), ('__gt__', lambda self, other: not self <= other)], '__gt__': [('__lt__', lambda self, other: not (self > other or self == other)), ('__ge__', lambda self, other: self > other or self == other), ('__le__', lambda self, other: not self > other)], '__ge__': [('__le__', lambda self, other: (not self >= other) or self == other), ('__gt__', lambda self, other: self >= other and not self == other), ('__lt__', lambda self, other: not self >= other)] }
Read also: http://regebro.wordpress.com/2010/12/13/python-implementing-rich-comparison-the-correct-way/
这篇关于Django RuntimeError:超出最大递归深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!