ValueError:在用户上设置`backend`属性

问题描述 投票:0回答:1

我在我的社交登录项目中添加了python-social-auth。我还为新用户提供了自己的注册表单。对于社交登录,我添加了一些身份验证后端。

现在,社交登录工作正常,但注册表单会导致一些问题。

输入详细信息并单击注册后,会出现此错误。

我在管理面板中看到,即使出现此错误,也会添加用户。

ValueError: You have multiple authentication backends configured and therefore must provide the `backend` argument or set the `backend` attribute on the user.

现在,它要求我设置用户的后端属性。怎么设置?

这是注册的视图,

def signup(request):
    if request.method == 'POST':
            form  = SignupForm(request.POST)
            if form.is_valid():
                    form.save()
                    username = form.cleaned_data.get('username')
                    raw_pass = form.cleaned_data.get('password')
                    user = authenticate(username=username,password=raw_pass)
                    login(request,user)
                    return redirect('location:get_location')
    else:
            form = SignupForm()
    return render(request, 'signup.html', {'form':form})

enter image description here

python django django-models django-forms
1个回答
0
投票

为我工作:

    if request.method == 'POST':
        form = UserCreateForm(request.POST)
        if form.is_valid():
            user = form.save()
            login(request, user, backend='django.contrib.auth.backends.ModelBackend')
            return redirect('/')
        else:
            pass
© www.soinside.com 2019 - 2024. All rights reserved.