1 回答

TA贡献1869条经验 获得超4个赞
我想你错过了一些过程。您没有allauth_2fa在 INSTALLED_APPS 中添加并且没有迁移它。我试着写下它的配置的完整过程。
第1步 :
pip install django-allauth-2fa
第2步 :
应用 settings.py 文件中的那些
INSTALLED_APPS = (
# Required by allauth.
'django.contrib.sites',
# Configure Django auth package.
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
# Enable allauth.
'allauth',
'allauth.account',
# Configure the django-otp package.
'django_otp',
'django_otp.plugins.otp_totp',
'django_otp.plugins.otp_static',
# Enable two-factor auth.
'allauth_2fa',
)
第 3 步:
MIDDLEWARE_CLASSES = (
# Configure Django auth package.
'django.contrib.auth.middleware.AuthenticationMiddleware',
# Configure the django-otp package. Note this must be after the
# AuthenticationMiddleware.
'django_otp.middleware.OTPMiddleware',
# Reset login flow middleware. If this middleware is included, the login
# flow is reset if another page is loaded between login and successfully
# entering two-factor credentials.
'allauth_2fa.middleware.AllauthTwoFactorMiddleware',
)
# Set the allauth adapter to be the 2FA adapter.
ACCOUNT_ADAPTER = 'allauth_2fa.adapter.OTPAdapter'
第四步:
python manage.py migrate
第 5 步:
现在你可以在你的视图文件中导入它也必须在 urls.py 文件中配置
添加回答
举报