Member-only story

Django Custom Authentication

Ramesh Ponnusamy
3 min readMay 26, 2020

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…

--

--

Ramesh Ponnusamy
Ramesh Ponnusamy

Written by Ramesh Ponnusamy

Data-Architect, SQL Master,Python ,Django, Flask dev, AI prompting, Linked-in: https://www.linkedin.com/in/ramesh-ponnusamy/ mail : ramramesh1374@gmail.com

No responses yet