# Authenticate or login in django
1. Open views.py
2. Import this line in views.py .
from django.contrib.auth import authenticate, login
3. Create function
eg.
class Auth(View):
def post(self, request, *args, **kwargs):
use = request.POST['username']
passw = request.POST['password']
user = authenticate(username=use, password=passw)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponse(login)
# Redirect to a success page.
else:
return HttpResponse("disable")
# Return a 'disabled account' error message
return HttpResponse("Invalid username or password ")
# Return an 'invalid login' error message."
1. Open views.py
2. Import this line in views.py .
from django.contrib.auth import authenticate, login
3. Create function
eg.
class Auth(View):
def post(self, request, *args, **kwargs):
use = request.POST['username']
passw = request.POST['password']
user = authenticate(username=use, password=passw)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponse(login)
# Redirect to a success page.
else:
return HttpResponse("disable")
# Return a 'disabled account' error message
return HttpResponse("Invalid username or password ")
# Return an 'invalid login' error message."