Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.shortcuts import render
- from django.http import HttpResponse, HttpResponseRedirect
- from django.contrib.auth import authenticate
- # Create your views here.
- def login_view (request):
- if request.method == "GET":
- # if request.GET['error'] == 'authfail':
- return render(request,'accounts/login.html')
- if request.method == "POST":
- username = request.POST['uname']
- password = request.POST['psw']
- user = authenticate(username=username, password=password)
- if user is not None:
- # A backend authenticated the credentials
- return HttpResponseRedirect('/')
- else:
- # No backend authenticated the credentials
- return HttpResponseRedirect('/login/?error=authfail')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement