python - “用户”对象没有属性 'is_verified'

标签 python django attributeerror two-factor-authentication django-two-factor-auth

我遇到了这个错误。突然之间,它在我的本地工作正常。但是当我尝试部署应用程序时出现此错误,我使用的是包 two_factor Otp,这是回溯 回溯:

File "/tmp/8d909c171bfae2c/antenv/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/tmp/8d909c171bfae2c/antenv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/tmp/8d909c171bfae2c/antenv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/tmp/8d909c171bfae2c/antenv/lib/python3.7/site-packages/django/contrib/admin/sites.py" in wrapper
  241.                 return self.admin_view(view, cacheable)(*args, **kwargs)

File "/tmp/8d909c171bfae2c/antenv/lib/python3.7/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/tmp/8d909c171bfae2c/antenv/lib/python3.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/tmp/8d909c171bfae2c/antenv/lib/python3.7/site-packages/django/contrib/admin/sites.py" in inner
  212.             if not self.has_permission(request):

File "/tmp/8d909c171bfae2c/antenv/lib/python3.7/site-packages/two_factor/admin.py" in has_permission
  28.         return request.user.is_verified()

File "/tmp/8d909c171bfae2c/antenv/lib/python3.7/site-packages/django/utils/functional.py" in inner
  257.         return func(self._wrapped, *args)

Exception Type: AttributeError at /
Exception Value: 'User' object has no attribute 'is_verified'

如有任何帮助,我们将不胜感激。谢谢

最佳答案

我认为这是因为你没有添加中间件。在你的settings.py中,找到MIDDLEWARE变量。下

'django.contrib.auth.middleware.AuthenticationMiddleware',

添加

'django_otp.middleware.OTPMiddleware', 

还要确保应用迁移:

python manage.py migrate

关于python - “用户”对象没有属性 'is_verified',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67291357/

相关文章:

python - 如何对 Python 列表进行部分排序?

python - 为什么我的循环每次迭代都需要更多内存?

python - keras 准确率提高不超过 59%

python - Django 反向 url 找到参数但失败关键字

python - AttributeError: 'NoneType' 对象没有属性 'get_text'

python - 如何修复属性错误: 'HTMLParserTreeBuilder' object has no attribute 'initialize_soup'

python - 我如何处理 django 嵌套模型?

python - 限制 Django 中内联表单集的外键查询集

python - AttributeError: 'Magic' 对象在使用 python-jira 时没有属性 'cookie'

python - Django 中基于类的 View 上的 login_required 装饰器