Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@clint74
Created February 21, 2019 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clint74/f97297afe1b0b52c2234c34c5a67c962 to your computer and use it in GitHub Desktop.
Save clint74/f97297afe1b0b52c2234c34c5a67c962 to your computer and use it in GitHub Desktop.
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