为了账号安全,请及时绑定邮箱和手机立即绑定

模型类 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 关注
  • 204 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信