亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

模型類 django_otp.plugins.otp_static.models.

模型類 django_otp.plugins.otp_static.models.

狐的傳說 2021-12-08 16:08:44
我正在嘗試使用這個庫。當我使用我自己的urls.py導入視圖時:from allauth_2fa import views我收到以下錯誤:   File "C:\Users\User\Desktop\Heroku\github\backup\main\urls.py", line 20, in <module>    from allauth_2fa import views  File "C:\Users\User\lib\site-packages\allauth_2fa\views.py", line 23, in <module>    from django_otp.plugins.otp_static.models import StaticToken  File "C:\Users\User\lib\site-packages\django_otp\plugins\otp_static\models.py", line 11, in <module>    class StaticDevice(Device):  File "C:\Users\User\lib\site-packages\django\db\models\base.py", line 95, in __new__    "INSTALLED_APPS." % (module, name)RuntimeError: Model class django_otp.plugins.otp_static.models.StaticDevice doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.我不明白是我做錯了什么,還是錯誤出在依賴模塊中。誰能幫我?
查看完整描述

1 回答

?
MMTTMM

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 文件中配置



查看完整回答
反對 回復 2021-12-08
  • 1 回答
  • 0 關注
  • 234 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號