我尝试使用实现模式表单的Django模块和使用电子邮件代替用户名的自定义用户模型注册后自动登录用户。由于某些原因,尝试使用authenticate方法对用户进行身份验证时,它将返回None且new_user的值为None。可能是由于自定义用户模型还是我使用的模块?
class SignUpView(BSModalCreateView):
form_class = CustomUserCreationForm
template_name = 'registration/signup.html'
success_message = 'Success: Sign up succeeded. You can now Log in.'
success_url = reverse_lazy('plan:plan')
def form_valid(self, form):
valid = super(SignUpView, self).form_valid(form)
email, password = form.cleaned_data.get('email'), form.cleaned_data.get('password1')
new_user = authenticate(email=email, password=password)
login(self.request, new_user)
return valid