尝试登录时遇到上述错误。我已经实现了django-users2
模块。以下是我正在使用的模块
Django Version: 2.1.5
Python Version: 3.6.7
Installed Applications:
['myapp.apps.MyAdminConfig',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'category',
'tag',
'parttimejob',
'myapp.core',
'jobtype',
'users',
'django_extensions',
'jobmessages',
'search',
'profiles',
'employers',
'employees',
'jobtemplates',
'tempus_dominus',
'social_django',
'background_task']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social_django.middleware.SocialAuthExceptionMiddleware']
跟踪:
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/contrib/admin/sites.py" in login
398. return LoginView.as_view(**defaults)(request)
File "/usr/local/lib/python3.6/dist-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/utils/decorators.py" in _wrapper
45. return bound_method(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
76. return view(request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/utils/decorators.py" in _wrapper
45. return bound_method(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/utils/decorators.py" in _wrapped_view
142. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/utils/decorators.py" in _wrapper
45. return bound_method(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/views.py" in dispatch
61. return super().dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/views/generic/base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/views/generic/edit.py" in post
141. if form.is_valid():
File "/usr/local/lib/python3.6/dist-packages/django/forms/forms.py" in is_valid
185. return self.is_bound and not self.errors
File "/usr/local/lib/python3.6/dist-packages/django/forms/forms.py" in errors
180. self.full_clean()
File "/usr/local/lib/python3.6/dist-packages/django/forms/forms.py" in full_clean
382. self._clean_form()
File "/usr/local/lib/python3.6/dist-packages/django/forms/forms.py" in _clean_form
409. cleaned_data = self.clean()
File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/forms.py" in clean
196. self.user_cache = authenticate(self.request, username=username, password=password)
File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/__init__.py" in authenticate
73. user = backend.authenticate(request, **credentials)
File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/backends.py" in authenticate
16. user = UserModel._default_manager.get_by_natural_key(username)
File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/base_user.py" in get_by_natural_key
44. return self.get(**{self.model.USERNAME_FIELD: username})
File "/usr/local/lib/python3.6/dist-packages/django/db/models/manager.py" in manager_method
82. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/users/managers.py" in get_queryset
55. return InheritanceQuerySet(self.model).select_subclasses()
File "/usr/local/lib/python3.6/dist-packages/model_utils/managers.py" in select_subclasses
20. self.model, levels=levels)
File "/usr/local/lib/python3.6/dist-packages/model_utils/managers.py" in _get_subclasses_recurse
103. rel for rel in model._meta.get_all_related_objects()
Exception Type: AttributeError at /admin/login/
Exception Value: 'Options' object has no attribute 'get_all_related_objects'
我已经提到了这个question并升级了django和djangorestframework,但它们似乎都不起作用。我是django的新手。请询问我可以提供的更多信息。请指导我解决错误。
答案 0 :(得分:1)
当然,升级DRF不能解决您的问题,因为该问题与DRF无关-它在InheritanceManager代码中,该代码来自django-models-utils和is a dependance of django-users-2。还有FWIW,the issue has been fixed 2 years ago,所以您的django-models-utils版本可能已经过时了。
请注意,您需要自己进行调试的所有工作是:1 /阅读回溯以找出问题发生的位置,2 /转到项目的gitlab,3 /搜索错误消息(或它-我在问题跟踪器中搜索了“ get_all_related_objects”)(也搜索了已解决的问题),4 /阅读了问题的描述,状态和解决方案。