Created
February 21, 2019 22:36
-
-
Save clint74/f97297afe1b0b52c2234c34c5a67c962 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpResponse, HttpResponseRedirect | |
from django.contrib.auth import authenticate, login | |
def login(request): | |
if request.POST: | |
username = request.POST['username'] | |
password = request.POST['password'] | |
user = authenticate(username=username, password=password) | |
if user is not None: | |
login(request, user) | |
# return render(request, 'home.html', {}, ) | |
try: | |
return HttpResponseRedirect('endereco que você quer direcionar') | |
except IndexError: | |
return HttpResponseRedirect('/') | |
else: | |
return render(request, 'login.html', { | |
'erro': 'O usuário ou senha incorretos' | |
}, ) | |
else: | |
return render(request, 'login.html', {}, ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment