We will start this section by using the Django authentication framework to allow users to log in to our website. Our view should perform the following actions to log in a user:
- Get the username and password by posting a form
- Authenticate the user against the data stored in the database
- Check whether the user is active
- Log the user into the website and start an authenticated session
First, we will create a login form. Create a new forms.py file in your account application directory and add the following lines to it:
from django import formsclass LoginForm(forms.Form): username = forms.CharField() password = forms.CharField(widget=forms.PasswordInput)
This form will be used to authenticate users against the database. ...