将2fa添加到Django项目

时间:2019-03-02 11:13:56

标签: python django two-factor-authentication

我正在尝试将2fa添加到我的Django网站中。我采用了this library

我当前的登录表单如下所示:

     if request.method == "POST":
            form = AuthenticationForm(request, data=request.POST)
            if form.is_valid():
                username = form.cleaned_data.get('username')
                password = form.cleaned_data.get('password')
                user = authenticate(username=username, password=password)


                if user is not None:
                    login(request, user)
                    messages.info(request, f"You are now logged in as {username}")
                    return redirect("main:homepage")
                else:
                    messages.error(request, "Invalid username or password")

            else:
                messages.error(request, "Invalid username or password")

但是从这里我真的不知道如何继续以及如何将库集成到此登录表单中。有人可以给我一些帮助,方向或已有的实施示例吗?预先感谢!

0 个答案:

没有答案