def login_view(request): if request.method == 'POST': user_form = UserLoginForm(request.POST) if user_form.is_valid(): user = user_form.login(request) if user: login(request, user) return redirect('main:shop') else: user_form = UserLoginForm() context = { 'user_form': user_form } return render(request, 'users/login.html', context)
def post(self, request): next_ = request.GET.get('next') if request.GET.get( 'next') is not None else reverse('home') if request.user.is_authenticated(): return HttpResponseRedirect(next_) form = UserLoginForm(request.POST) if form.is_valid(): user = form.login(request) if user: login(request, user) return HttpResponseRedirect(next_) return render(request, 'login.html', { 'login_form': form, 'next': next_ })