5. You want to customize the login form to add a 'Remember Me' checkbox that keeps users logged in longer. Which approach correctly integrates this feature using Django's LoginView?
hard
A. Override LoginView to add a custom form with a 'remember_me' field and adjust session expiry in form_valid
B. Add a checkbox in the template only; Django handles session duration automatically
C. Set template_name to a new template with the checkbox but do not change the view or form
D. Use Django's default LoginView without changes; 'Remember Me' is built-in
Solution
Step 1: Understand customizing LoginView
To add new fields like 'Remember Me', you must create a custom form and override LoginView to use it.
Step 2: Adjust session expiry based on 'remember_me'
Override form_valid method to set session expiry longer if 'remember_me' is checked.
Final Answer:
Override LoginView to add a custom form with a 'remember_me' field and adjust session expiry in form_valid -> Option A
Quick Check:
Custom form + override form_valid for 'Remember Me' [OK]
Hint: Customize form and override form_valid to handle 'Remember Me' [OK]
Common Mistakes:
Adding checkbox only in template without backend logic