Jack022
Jack022

Reputation: 1257

Django - importing view from Dependency

I'm trying to use this library since i want to add 2FA Auth to my project. In order to integrate the module in my project, i need to import their views to my urls.py file, right?

I tried to import SetupView, but i'm getting this error: module 'allauth_2fa.views' has no attribute 'homepage'. Here is what i understood: it looks like if i import a view from the dependency, it will only read those views from the dependency but not my own views declared on views.py.

from django.urls import path
from . import views
from django.conf.urls import url, include

from django.conf.urls import url

from allauth_2fa import views

app_name = "main"

urlpatterns = [

    path("setup/", views.TwoFactorSetup.as_view(), name="setup"),

    path("", views.homepage, name="homepage"),
    path("register/", views.register, name="register"),
    path("logout/", views.logout_request, name="logout"),
    path("login/", views.login_request, name="login"),

]

Extra: SetupView will generate the page required to enable the 2FA authentication, that's why i need it. Later i will also import the other views required to have my two factor authentication fully running

Upvotes: 0

Views: 143

Answers (1)

Andrei Berenda
Andrei Berenda

Reputation: 1986

At first you imported

from . import views

And then:

from allauth_2fa import views

And after that you tried to do:

path("", views.homepage, name="homepage"),

And views is allauth_2fa.views not from your project

So you just need to do like this:

from allauth_2fa import views as allauth_2fa_views

And then use it when you need

Upvotes: 1

Related Questions