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 文件中配置
添加回答
舉報