Adding login and registration in Django

Adding login and registration is very straight forward in Django. Note that Django provides a built in User model.

User model exists ONLY for authentication. Use the User model to only store absolutely necessary info for authentication. Like Username and password (or if using custom user model, email and password.. I usually make the email as the unique field). Nothing else. Anything else, like gender, blah blah blah goes in other models like profile etc.

Please see here on how to make a custom User model.

NEVER access User model directly. Use the get_user_model() method provided by Django. This is so that we keep everything DRY and only change the User model in settings (if we have to).

Three simple steps:

  1. Make the Django forms for login and registration
  2. Implement the view logic for login and registration
  3. Do the wiring in

For Django forms, I have created a file at the same level as

Now comes the view logic in

Now comes the

No Comments

You can leave the first : )

Leave a Reply

Your email address will not be published. Required fields are marked *