1from django.contrib.auth import authenticate, login
2
3def my_view(request):
4 username = request.POST['username']
5 password = request.POST['password']
6 user = authenticate(request, username=username, password=password)
7 if user is not None:
8 login(request, user)
9 # Redirect to a success page.
10 ...
11 else:
12 # Return an 'invalid login' error message.
13 ...
14