django-use-email-as-username (2023)

Project description

django-use-email-as-username (1)django-use-email-as-username (2)django-use-email-as-username (3)django-use-email-as-username (4)

A Django app to use email as username for user authentication.


  • Custom User model with no username field

  • Use email as username

  • Includes a django-admin command for quick install

  • Follow Django best practices for new Django projects and User models.


  1. Install Django use Email as Username:

    # Run in your terminalpip install django-use-email-as-username
  2. Add it to your INSTALLED_APPS:

    # In your fileINSTALLED_APPS = ( ... 'django_use_email_as_username.apps.DjangoUseEmailAsUsernameConfig', ...)
  3. Create your new django app:

    # Run in your terminalpython create_custom_user_app
  4. Add the new app to your INSTALLED_APPS:

    # In your fileINSTALLED_APPS = ( ... 'django_use_email_as_username.apps.DjangoUseEmailAsUsernameConfig', 'custom_user.apps.CustomUserConfig', ...)
  5. Now instruct Django to use your new model:

    # In your fileAUTH_USER_MODEL = 'custom_user.User'
  6. Create and run migrations:

    # Run in your terminalpython makemigrationspython migrate

You now have a new Django app which provides a custom User model.

You can further modify the new User Model any time in the future, just rememberto create and run the migrations.


This app gives you a custom User model, which is good practice for newDjango projects.

Changing to a custom user model mid-project is not easy.

It is recommended to always create a custom User model at the beginning of everyDjango project.

(Video) Use Email Instead of Username in Django Authentication | Email Login


Tools used in rendering this package:

Project details


View statistics for this project via, or by using our public dataset on Google BigQuery


License: BSD License (BSD-3-Clause)

Author: Federico Jaramillo Martínez

Tags django, email, auth, username

Requires: Python >=3.5


django-use-email-as-username (5) jmfederico

Release history Release notifications | RSS feed

django-use-email-as-username (9)

(Video) How to Login with Email | Easy method using python and Django 4 | Mastery Tips and Tricks #45


(Video) Django Custom User Model | Email as Username | Phone as Username | Authentication Example |Code Band

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

(Video) Custom User Model Login with Email Address - DJANGO 3.x

Source Distribution

django-use-email-as-username-1.2.0.tar.gz (5.9 kB view hashes)

Uploaded source

Built Distribution

django_use_email_as_username-1.2.0-py3-none-any.whl (7.8 kB view hashes)

Uploaded py3


Hashes for django-use-email-as-username-1.2.0.tar.gz

Hashes for django-use-email-as-username-1.2.0.tar.gz
Algorithm Hash digest
SHA256 5679ca6f29ac345aba12b85cbf508f4455fa9b4a6697b3ef45bc9c8b8e0e348f
MD5 0b540c73875a6eb5e229b1e20d08e53d
BLAKE2b-256 9f337828bfca6116f6b23331ef8c9d77f1904e6afeb765db8d7a2f33c4ce2f62



Hashes for django_use_email_as_username-1.2.0-py3-none-any.whl

Hashes for django_use_email_as_username-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 117bca14e67ab1adc17737483f1086a901f3cf33dbd7aea5c1aac2ec05c3e6ea
MD5 349d6995d8c826bdd01dc9a2c183e836
BLAKE2b-256 400d463678288ce54b1e37bda8621ea5759afd869b567ee09aa1cdb52da6c21d


(Video) #4 Django Tutorial: How to allow users to login with both username or email ?


How to use email and password for login in Django? ›

Authentication forms

By default, the UserCreationForm only takes the username and password fields (with its verification input). So, we can modify this by creating a new class called RegisterForm which extends the default form. Then, we specify the required fields to create a new user (email, username, and password).

How to change username field in Django? ›

As we all know the default User model in django uses a username to uniquely identify a user during authentication. If you need to replace this username field with other field lets say an email field then you need to create a custom user model by either subclassing AbstractUser or AbstractBaseUser.

How to make email address unique in Django? ›

You have to declare the email field in your AbstractBaseUser model as unique=True .

Which method should you override in order to authenticate a user with their email instead of username? ›

For using email/username and password for authentication instead of the default username and password authentication, we need to override two methods of ModelBackend class: authenticate() and get_user():

What does {% %} do in Django? ›

{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.

How does Django integrate with email? ›

Sending Emails with the Django Shell

We import the Django send_mail function. Then we import the settings object which contains all the global settings and the per-site settings (those inside the file). Finally, we pass all the needed arguments to the send_mail function.

How to make username unique in Django? ›

If you want to use django's default authentication backend you cannot make username non unique. You will have to implement a class with get_user(user_id) and authenticate(request, **credentials) methods for a custom backend.

How do I customize my username? ›

What to Know
  1. Incorporate your favorite things, such as food, celebrities, or career aspirations.
  2. Use an online screen name generator such as SpinXO.
  3. Build an unlikely username by substituting symbols and letters, like 3 for E and $ for 5.
Jun 1, 2022

How do I change username properties? ›

Change username
  1. Open the Control Panel.
  2. Double-click the Users and Password icon.
  3. Make sure "Users must enter a user and password to use this computer" is checked.
  4. Highlight the account you want to change the username for and click the Properties button.
  5. In Properties, you can change the username.
Dec 5, 2021

Is email good unique identifier? ›

Reason 1: Email is not a guaranteed unique identifier

Email is a means of contacting its owner/recipient. It is no different than a telephone number. Institutions may not enforce that multiple individuals not use the same email address when communicating with the institutions (domestic partners, siblings, etc.

How do I create a unique email name? ›

Creative email names that are still available
  1. Use the first letter of your first name together with your full last name; e.g. j.smith.
  2. Include your middle name; e.g. john. ...
  3. Use a nickname plus your last name; e.g. johnny. ...
  4. Switch around the word order; e.g. smith. ...
  5. Include special characters; e.g. “.” or “-“ or “_”

Should email be unique in database? ›

Answer: The unique email constraint determines whether constituents can register with an email address that is already in the system. By not forcing the unique email constraint, you are more prone to having duplicates in your database which may cause other issues down the road if they aren't resolved.

What are the three 3 main types of authentication techniques? ›

Authentication factors can be classified into three groups: something you know: a password or personal identification number (PIN); something you have: a token, such as bank card; something you are: biometrics, such as fingerprints and voice recognition.

What does {% include %} do? ›

The include tag allows you to include a template inside the current template. This is useful when you have a block of content that is the same for many pages.

Is Django a good skill? ›

Django is an undeniably valuable tool in any developer's skill set — but getting started with it can be challenging. In the below sections, we'll share everything you need to know before you learn Django, as well as the framework's history, structure and setup.

Why is {% extends %} tag used? ›

The extends tag is used to declare a parent template. It should be the very first tag used in a child template and a child template can only extend up to one parent template. To summarize, parent templates define blocks and child templates will override the contents of those blocks.

How do I bypass Django username and password? ›

from django.contrib.auth import authenticate, login def my_view(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) if user is not None: login(request, user) # Redirect to a success page. ... else: # Return an 'invalid ...

Do professionals use Django? ›

Django is a Python-based web framework giving developers the tools they need for rapid, hassle-free development. You can find that several major companies employ Django for their development projects. Here are 9 global companies using Django: Instagram.

Can you embed email? ›

Email providers, like Gmail, allow you to drag an image from a folder and drop it into an area inside the compose box that says “attach files here”. Gmail will automatically embed the image and realign it so it's in line with the rest of the plain text.

What should I put my username as? ›

Avoid using the beginning of your email address as your username. Your username should be simple enough to remember but hard to guess. Never use easy-to-guess numbers with your usernames (for example, address or date of birth). Don't use your Social Security number or ID number as your username.

How to create a custom user in Django? ›

Step 1: Set up a Django project.
  1. Create a python virtual environment and activate it.
  2. Install Django and Django rest framework. pip install django djangorestframework.
  3. Start a new project: django-admin startproject config .
  4. Run the following command to see if the installation is correct.
Mar 17, 2022

Does Django automatically create ID? ›

An id field is added automatically, but this behavior can be overridden. See Automatic primary key fields. The CREATE TABLE SQL in this example is formatted using PostgreSQL syntax, but it's worth noting Django uses SQL tailored to the database backend specified in your settings file.

Is a username the same as an email address? ›

Most people think email names and email usernames are the same things. They're not. An email name (also known as a sender name) is the name that's displayed when you send an email. Your email username, however, is your email address.

Should your username be your real name? ›

If you need an account on a site that you don't want associated with your online reputation, don't use your real name or a common derivative of it. You want to avoid having a Google search of your name lead to these profiles. Try to pick something completely unrelated to your name that you'll be able to remember.

How do I create a username for example? ›

Some sample username schemes include:
  1. [first name]. [last name]
  2. [first initial]. [last name]
  3. [first name]. [last name]_[class year]
Jan 10, 2017

What is a property username? ›

The UserName property holds the name of the user account under which the specified application process is running.

How do I change my username in Command Prompt? ›

To change the user account name through the Command Prompt, you must first open it and then type the following commands: net user (for example, net user mahmud newname) Press Enter after you enter the above command. Your account name will be changed to .

How do I change my Hashnode username? ›

Change Username

If you want to change your username, send an email to with the same email address you used to create your Hashnode blog. We will send you an update via email after we've changed your username.

What is the most untraceable email? ›

7 Anonymous Email Account Providers
  • ProtonMail. ProtonMail is one of the best anonymous email service providers and it's free! ...
  • Tutanota. In many ways, Tutanota is right up there with ProtonMail — you can't really go wrong with it. ...
  • Mailfence. ...
  • AnonAddy. ...
  • Private-Mail. ...
  • Hushmail. ...
  • CounterMail.
Nov 1, 2022

What are the advantages of email id? ›

The Advantages of Email for Internal Communications
  • Email is a free tool. ...
  • Email is quick. ...
  • Email is simple. ...
  • Email allows for easy referencing. ...
  • Email is accessible from anywhere – as long as you have an internet connection. ...
  • Email is paperless, and therefore, beneficial for the planet.
Feb 18, 2020

What should not be using your official email id? ›

Never use an email id like or Before we get into the email, I want to remind you of some quick pointers.
  • Bad Subject line. ...
  • Improper greeting/closing sentence. ...
  • Too lengthy/ Too short. ...
  • Spelling and Grammatical errors. ...
  • Too formal/ Too informal. ...
  • Not monitoring the tone.
Jun 14, 2019

Can I use my full name as email address? ›

It is safe and professional to use your real name as an email address. Having a safe username or email address takes care of your privacy. At the same time, using your real name as your email address gives an impression of a professional and credible person behind the email.

How do I create a free alias email address? ›

In Gmail, go to settings -> Accounts and Import and click Add another email address. This will pop up a new small window where you will enter in the details of the alias. Enter the name you want recipients to view and the address of the alias. Make sure the "Treat as an alias" box is checked.

Is info@ a good email? ›

Email Address Tips

Do not use info@. That is an email address that spammers target. Instead, think of something more creative: hello@, contact@, letstalk@. Anything but info@, which will increase your spam levels exponentially!

Can I use email as the primary key? ›

Yes, you can use email address as Primary Key in databases. Because it is already an unique one. Thats why it is used as Username also in most webapplications.

Can I use email ID as a primary key? ›

Yes, it is a bad primary key because your users will want to update their email addresses. Save this answer. Show activity on this post. Another reason why integer primary key is better is when you refer to email address in different table.

Why you shouldn't use just in emails? ›

Amanda Hesser and Merrill Stubbs, co-founders of Food52, once commented that adding “just” to your emails makes you seem less confident. After taking a look at previous emails I've sent, I really have to agree. Saying things like, “Just checking in” or “Just wanted to ask a question” minimizes your request.

What is the most commonly used user authentication technique? ›

Password-based authentication

Also known as knowledge-based authentication, password-based authentication relies on a username and password or PIN. The most common authentication method, anyone who has logged in to a computer knows how to use a password.

What is the most common way to authenticate users? ›

Passwords are the most common methods of authentication. Passwords can be in the form of a string of letters, numbers, or special characters. To protect yourself you need to create strong passwords that include a combination of all possible options.

What are those 4 commonly authentication methods *? ›

Common biometric authentication methods include fingerprint identification, voice recognition, retinal and iris scans, and face scanning and recognition.

What is the strongest authentication method? ›

1. Biometric Authentication Methods. Biometric authentication relies on the unique biological traits of a user in order to verify their identity. This makes biometrics one of the most secure authentication methods as of today.

What is the strongest form of authentication? ›

Biometric authentication is the strongest form of authentication.

What is the difference between authorization vs authentication? ›

Authorization. Authentication and authorization are two vital information security processes that administrators use to protect systems and information. Authentication verifies the identity of a user or service, and authorization determines their access rights.

What are different ways a user can be authenticated other than username password? ›

Here are just a few of those methods.
  • Single-Factor/Primary Authentication. ...
  • Two-Factor Authentication (2FA) ...
  • Single Sign-On (SSO) ...
  • Multi-Factor Authentication (MFA) ...
  • Password Authentication Protocol (PAP) ...
  • Challenge Handshake Authentication Protocol (CHAP) ...
  • Extensible Authentication Protocol (EAP)
Sep 30, 2020

How does Django authentication work? ›

The Django authentication system handles both authentication and authorization. Briefly, authentication verifies a user is who they claim to be, and authorization determines what an authenticated user is allowed to do. Here the term authentication is used to refer to both tasks.

How does Django validate email and password? ›

Django provides several validation methods for checking email address validity. The easiest way is to import the validate_email method from the core validators module. This is a standalone function that can be used in any models, forms, or views.

How do I add login requirements in Django? ›

Create an app folder in the django project folder. Add template folder in the django folder and provide its path in django_folder > . Create file named as in the app folder and provide its path in django_project > Add login decorator to the function in app_folder >

How does Django validate username and password? ›

validate(self, password, user=None) : validate a password. Return None if the password is valid, or raise a ValidationError with an error message if the password is not valid. You must be able to deal with user being None - if that means your validator can't run, return None for no error.

How do I create a login form in Django? ›

A Guide to User Registration, Login, and Logout in Django
  1. Create the register form.
  2. Create a register.html file.
  3. Add a register URL to the app.
  4. Add a register function to the views.
  5. Test the register user functionality.

How to verify user email in Django? ›

The app takes care of :
  1. Settings user's is_active status to False.
  2. Generate hashed token for each user.
  3. Generate a verification link and send it to the user's email.
  4. Recieve a request from the verification link and verify for its validity.
  5. Activating the user's account.

Can we create user without password in Django? ›

Programmatically, you can create / save a new User without a password argument, and it will not raise any exceptions. In fact, you can even create a user without any arguments.

How do you automate a login in Python? ›

The following steps will be performed using Python and Selenium.
  1. Import the Libraries.
  2. Create Variables for Login Credentials.
  3. Install the Web Driver.
  4. Launch the Browser and Open the URL.
  5. Enter Login Credentials and Sign In.
  6. Verify Login Status.

How does Django handle login? ›

Overview. The Django authentication system handles both authentication and authorization. Briefly, authentication verifies a user is who they claim to be, and authorization determines what an authenticated user is allowed to do. Here the term authentication is used to refer to both tasks.

Is username unique in Django? ›

Even though the username field is marked as unique, by default it is not case-sensitive.

Is username unique in Django user model? ›

The default User model in Django uses a username to uniquely identify a user during authentication. If you'd rather use an email address, you'll need to create a custom User model by either subclassing AbstractUser or AbstractBaseUser .

How do I validate a username? ›

A username is considered valid if all the following constraints are satisfied:
  1. The username consists of 6 to 30 characters inclusive. ...
  2. The username can only contain alphanumeric characters and underscores (_). ...
  3. The first character of the username must be an alphabetic character, i.e., either lowercase character.
Oct 16, 2020

How do I create a custom login and registration page? ›

Let's go - here are the main steps:
  1. Install and activate the user registration plugin.
  2. Activate the user registration add-on.
  3. Create a custom login form.
  4. Create a custom registration form.
  5. Customize the WordPress login and registration page.


1. Django: Creating an Email based Authentication Backend
2. Django tutorials for beginners - 45 Unique Email in Form
(Coding Point)
3. Django Tutorial - User Registration with Email Confirmation #15
(Python Lessons)
4. Django : How to use email instead of username for user authentication?
(Knowledge Base)
5. Django Tutorial - Django Decorators and email login #10
(Python Lessons)
6. Custom User Model | Explore Django
(Code With Stein)
Top Articles
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated: 10/31/2022

Views: 5622

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.