def login_view(request): # form = LoginForm() # context = {'form': form} # http_response = render(request, 'login.html', context) # return HttpResponse(http_response) if request.user.is_authenticated: return HttpResponseRedirect('/pictures') if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] pw = form.cleaned_data['password'] user = authenticate(username=username, password=pw) if user is not None: login(request, user) return HttpResponseRedirect('/pictures') else: form.add_error('username', 'Login failed') else: form = LoginForm() context = {'form': form} http_response = render(request, 'login.html', context) return HttpResponse(http_response)
def login_view(request): if request.user.is_authenticated: return HttpResponseRedirect('/pictures') if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] pw = form.cleaned_data['password'] user = authenticate(username=username, password=pw) if user is not None: login(request, user) return HttpResponseRedirect('/pictures') # why do I have to put /pictures here and not in the def root? else: form.add_error('username', 'Login failed') else: form = LoginForm() return render(request, 'login.html', {'form': form})
def login_view(request): if request.user.is_authenticated: return HttpResponseRedirect("/pictures") if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data["username"] pw = form.cleaned_data["password"] user = authenticate(username=username, password=pw) if user is not None: login(request, user) return HttpResponseRedirect("/pictures") else: form.add_error("username", "Login failed") else: form = LoginForm() context = {"form": form} http_response = render(request, "login.html", context) return HttpResponse(http_response)
def login_view(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] pw = form.cleaned_data['password'] user = authenticate(username=username, password=pw) if user is not None: login(request, user) return redirect(reverse('show_all')) else: form.add_error('username', 'Login failed') else: form = LoginForm() return render(request, 'registration/login.html', { 'form': form })