Email + Social Logins in Django - Step-by-Step Guide

Email and social logins are common techniques for websites and apps to allow users to establish accounts or check in. Users must provide their email address and password for email login, however, social login allows users to sign in using their social networks accounts, such as Facebook or Google. In this tutorial, we'll go through how to set up email and social logins in Django.


With Django, there are numerous ways to incorporate email and social logins. The Django-allauth package, which supports authentication for numerous login methods, including email and social logins, is one of the most prevalent. Another approach is to utilize the Django-social-auth package, which offers social authentication for a variety of social networking services.


Django-allauth installation −

pip install django-allauth

Django-social-auth installation −

pip install django-social-auth

The following code illustrates the use of Django-allauth to implement email and social logins in Django −


  • Django-allauth or Django-social-auth should be installed.

  • In, configure authentication backends.

  • In, include allauth URLs.

  • To construct database tables, and run migrations.

  • Configure an email backend for email verification.

  • Modify templates to match the look of your website.

Include the following URLs in

path('accounts/', include('allauth.urls')),

In, the line of code "path('accounts/', include('allauth.urls'))" contains the URLs given by the Django-allauth package, which manages authentication for multiple login methods, including email and social logins. This line of code translates the URL "accounts/" to the allauth URLs, allowing users to access the Django-allauth authentication views.

Run migrations to create the necessary database tables.

Set up the email backend in to enable email verification:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

Customize the templates in templates/account/ to match your site's design.

Follow these steps to create the project's environment and directory −

  • Python and pip should be installed.

  • With virtualenv or venv, create a virtual environment.

  • Turn on the virtual environment.

  • With pip, install Django.

  • With the "django-admin startproject" command, create a new Django project.

  • With the "python startapp" command, create a new Django app within the project.

  • In, add the new app to the INSTALLED APPS list.

  • In, define the app's models.

  • Using the "python makemigrations" and "python migrate" commands, create the database tables.

  • In, configure the authentication backends.

  • Use the code line "path('accounts/', include('allauth.urls'))" to include the allauth URLs in

  • In, configure an email backend for email verification.

  • Modify the templates in templates/account/ to match the style of your site.

  • Use "python runserver" to start the Django development server and test the email and social logins.


The first piece of code (in should be added to your project's file, which is where you establish the configuration settings for your Django project.



   'google': {
      'APP': {
         'client_id': 'YOUR_CLIENT_ID',
         'secret': 'YOUR_SECRET_KEY',
         'key': ''
   'facebook': {
      'APP': {
         'client_id': 'YOUR_CLIENT_ID',
         'secret': 'YOUR_SECRET_KEY',
         'key': ''

The second piece of code (in should be added to your project's file, where you specify your Django project's URL patterns.

from django.urls import path, include

urlpatterns = [
   path('accounts/', include('allauth.urls')),

Remember to change the "YOUR CLIENT ID" and "YOUR SECRET KEY" values with your real Google and Facebook developer console credentials. Finally, before executing your Django project, be sure to install any required packages (such as Django-allauth).


Users may establish accounts or sign in using their email or social media accounts after integrating email and social logins using Django-allauth or Django-social-auth.


Using email and social logins in Django can improve the user experience and make the account creation process easier. Utilizing packages like Django-allauth or Django-social-auth can make the implementation process smoother and faster.

Updated on: 22-May-2023


Kickstart Your Career

Get certified by completing the course

Get Started