Advertisement
Guest User

aaa

a guest
Sep 30th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1.  
  2. from django.shortcuts import render
  3. from django.http import HttpResponse, HttpResponseRedirect
  4. from django.contrib.auth import authenticate
  5.  
  6. # Create your views here.
  7. def login_view (request):
  8. if request.method == "GET":
  9. # if request.GET['error'] == 'authfail':
  10. return render(request,'accounts/login.html')
  11. if request.method == "POST":
  12. username = request.POST['uname']
  13. password = request.POST['psw']
  14. user = authenticate(username=username, password=password)
  15. if user is not None:
  16. # A backend authenticated the credentials
  17. return HttpResponseRedirect('/')
  18. else:
  19. # No backend authenticated the credentials
  20. return HttpResponseRedirect('/login/?error=authfail')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement