Posts

Showing posts from November, 2020

How to Use Email as Username for Django Authentication

 Models.py:   from django.db import models from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin from django.utils import timezone from django.conf import settings # Create your models here. class UserManager ( BaseUserManager ): def create_user ( self , email , password = None , ** extra_fields ): """creae and save new user""" if not email: raise ValueError ( 'User must have a email address' ) if not password: raise ValueError ( 'User must have a password' ) user = self .model( email = self .normalize_email(email), **extra_fields) user.set_password(password) user.save( using = self .db) return user def create_superuser ( self , email , password ): """Create and save new super user""" user = self .create_user(email, password) user.is_staff...

Make directory if not there

 if not os.path.isdir(path):             os.mkdir(path)