猿问

模型类 django_otp.plugins.otp_static.models.

我正在尝试使用这个库。当我使用我自己的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.

我不明白是我做错了什么,还是错误出在依赖模块中。谁能帮我?


狐的传说
浏览 236回答 1
1回答

MMTTMM

我想你错过了一些过程。您没有allauth_2fa在 INSTALLED_APPS 中添加并且没有迁移它。我试着写下它的配置的完整过程。第1步 :pip install django-allauth-2fa第2步 :应用 settings.py 文件中的那些INSTALLED_APPS = (&nbsp; &nbsp; # Required by allauth.&nbsp; &nbsp; 'django.contrib.sites',&nbsp; &nbsp; # Configure Django auth package.&nbsp; &nbsp; 'django.contrib.auth',&nbsp; &nbsp; 'django.contrib.contenttypes',&nbsp; &nbsp; 'django.contrib.sessions',&nbsp; &nbsp; # Enable allauth.&nbsp; &nbsp; 'allauth',&nbsp; &nbsp; 'allauth.account',&nbsp; &nbsp; # Configure the django-otp package.&nbsp; &nbsp; 'django_otp',&nbsp; &nbsp; 'django_otp.plugins.otp_totp',&nbsp; &nbsp; 'django_otp.plugins.otp_static',&nbsp; &nbsp; # Enable two-factor auth.&nbsp; &nbsp; 'allauth_2fa',)第 3 步:MIDDLEWARE_CLASSES = (&nbsp; &nbsp; # Configure Django auth package.&nbsp; &nbsp; 'django.contrib.auth.middleware.AuthenticationMiddleware',&nbsp; &nbsp; # Configure the django-otp package. Note this must be after the&nbsp; &nbsp; # AuthenticationMiddleware.&nbsp; &nbsp; 'django_otp.middleware.OTPMiddleware',&nbsp; &nbsp; # Reset login flow middleware. If this middleware is included, the login&nbsp; &nbsp; # flow is reset if another page is loaded between login and successfully&nbsp; &nbsp; # entering two-factor credentials.&nbsp; &nbsp; '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 文件中配置
随时随地看视频慕课网APP

相关分类

Python
我要回答