Member-only story
Django Custom Authentication
Setting up the User-Management module is a hard-knock for developers.
Django comes with an aid box called Auth Model to help us to achieve this in shortened code.
Django allows us to modify the authentication method according to our requirements like login with a phone number, email rather than username.
Let’s take an example:
Note: Before starting the project make sure that you activated virtualenv and installed django package in that virtaulenv.
Create a project:
django-admin startproject Django_Custom_Auth
Navigate into that newly created project:
cd Django_Custom_Auth
Create a new app:
python manage.py startapp accounts
and in accounts, we are going to overwrite the authentication model.
in accounts/models.py:
first, create a model for extending the existing user model as follows:
from django.db import models
from django.contrib.auth.models import AbstractUser, BaseUserManager
class User(AbstractUser):
username = None
phone = models.CharField(verbose_name='Mobile Number', max_length=10, unique=True)
fcm_id = models.CharField(max_length=255…