pythondjangoattributeerrortwo-factor-authenticationdjango-two-factor-auth

'User' object has no attribute 'is_verified'


I'm having this error. All of a sudden it was working fine on my local. but when I tried to deploy the app I have this error, I'm using a package two_factor Otp, here is the traceback Traceback:

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'

any help would be appreciated. thank you


Solution

  • I think this is because you didn't add the middleware in. In your settings.py, find the MIDDLEWARE variable. Under

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

    add

    'django_otp.middleware.OTPMiddleware', 
    

    Also make sure do apply the migrations:

    python manage.py migrate