标签云

微信群

扫码加入我们

WeChat QR Code

I am using Django built-in authentication. A user can be login by username and password from django login form. But I want the user to be able to login with email id and password too.The login form has onlyusername field. Can we use this login field to enter an email id or username and authenticate the user.This is my django login viewsclass LoginForm(generic.CreateView):print("login")form_class = LoginFormtemplate_name = "feed/SignUp.html"def get(self, request):form = self.form_class(None)return render(request, self.template_name, {'form': form})def post(self, request):form = self.form_class(request.POST)if form.is_valid():UserModel = get_user_model()username = request.POST['username']password = request.POST['password']user = authenticate(request, username=username, password=password)if user is not None:if user.is_active:login(request, user)return redirect('')else:print(form.errors)My idea is same as like we can log in to GitHub account either by username or by email. What should I do to achieve this?