How to automatically log in users in with Django

Django does not automatically log in users after signing in, but achieving this functionality only takes a few extra lines of code.


I’m using Class-based Views. To automatically log in a user, we have to override the form_valid() method of the CreateView class. The form_valid() method is the last block of code to be run before redirecting the user to the success_url.

Full-stack developer and Django enthusiast. When I can’t find Django tutorials, I write them.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store