0

我有这个网址:(Django 2.0)

re_path('auth/(?P<code_>[a-zA-Z0-9]{12})/(?P<email_>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/$', homePageView.autenticate, name='autenticate'),

在我的views.py中:

class homePageView(TemplateView):
    template_name = 'index.html'

def autenticate(self, email_, code_):
    try:
        user = Usuario.objects.get(email=email_,activated_code=code_)
        code = user.two_factors_auth_code
        if (not user.two_factors_auth) and (code == code_) and (len(code) == 12):
            user.next_login = True
        user.save()
        return redirect('home')
    except Usuario.DoesNotExist:
        return redirect('home')

我希望我可以在我的认证方法中登录用户,但我的函数中没有请求参数。

¿ 如何将我的 autenticate 功能转换为另一个?

class homePageView(TemplateView):
    template_name = 'index.html'

def autenticate(self, request, email_, code_):
    try:
        user = Usuario.objects.get(email=email_,activated_code=code_)
        code = user.two_factors_auth_code
        if (not user.two_factors_auth) and (code == code_) and (len(code) == 12):
            user.next_login = True
        user.save()
        ####################
        login(request,user)
        ####################
        return redirect('home')
    except Usuario.DoesNotExist:
        return redirect('home')
4

1 回答 1

0

您在基于功能的视图等视图中使用身份验证方法。

在这个方法中,第一个参数是请求。仅将第一个参数重命名为 request 并完成

于 2018-07-08T10:26:24.737 回答