Tag: Django Authentication

Django Authentication With Custom User Model

By default, Django uses a built-in User model for authentication. If you’d like a basic tutorial on how to implement login, log out, sign up you can see the Django Authentication SignUpView -LoginView-LogoutView

However, the Django documentation highly recommends using a custom user model for a real-world project. Because this provides far more flexibility. In todays’ article, we will see how to create a custom user model for Django projects.

The default User model in Django uses a username to uniquely identify a user during authentication. We can create a custom Django user model by either subclassing AbstractUser or AbstractBaseUser. The difference is AbstractUser uses the existing fields of the User model and just allows to remove the username field.

On the contrary, AbstractBaseUser is used if one wants to start from scratch by creating completely a new User model. Here we will use  AbstractBaseUser

Firstly, we have created a Django project called ‘CUSTOM_AUTHENTICATION’ and an app named ‘custom_auth’. Now we are all set to start our work. So, without further ado let’s create our CustomUser model first.

Read More

Django Authentication SignUpView -LoginView-LogoutView

In this tutorial, we’ll discuss ‘how to allow users to log in to a website with their own accounts and how to allow them to create accounts. The mechanisms work behind the scene is called authentication.

Authentication verifies a user if he is who he pretends to be, and authorization determines what an authenticated user can do.

Django by default has a user authentication system. It handles user accounts, groups, permissions and cookie-based user sessions. We will discuss the following topics here:

  • Default User Model
  • Creating User
  • Creating Super User
  • Authenticating User
  • Authentication Views
    • Log In
    • Log Out
    • Sign Up / Registration

Read More

Powered by WordPress & Theme by Anders Norén