Django Allauth Tutorial – (Step by Step)

User registration has become an integral part of any web application now. Coding a user registration may be a pain but there are plugins like. django-registration-redux and django allauth which makes social authentication easy.

Maintaining your user registration may be difficult and may not lead to many conversions, as the user has to fill in all the details again and again. Here’s where social registrations come into play and help with the easy registration process for both users and the developer.

Social authentication also helps in high registrations compared to normal user registration and helps obtain extra user information. Not everything is good in this authentication process. It may also be a disadvantage to using a third party API for the registration process. Like you may not have complete control over the user model, etc.

The package Django allauth helps to integrate social logins from Github, Gmail, Facebook among others in just a few steps.

Setup Django allauth

Follow the below steps to setup a django project

  • Create a Django project if you already don’t have one.
  • Install Django allauth using the command pip install django-allauth
  • Add 'allauthallauth.account'allauth.socialaccount and all the necessary social logins to INSTALLED_APPS.
  • After you configure your installed apps section, it has to be similar to the code below:

You can read entire list of supported api on the installation page.

We need to Configure the template context processor settings in and also add URL pattern in the project

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.normpath(os.path.join(BASE_DIR, 'templates')),
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
 # Already defined Django-related contexts here

                # `allauth` needs this from django


Now add the following authentication backend code at the bottom of

     # Needed to login by username in Django admin, regardless of `allauth`

    # `allauth` specific authentication methods, such as login by e-mail

Copy the template files from the django-allauth repository and paste them in the templates folder in your project directory.

Add the allauth URLs in of your main project directory. You can use any suffix you want but the official documentation uses accounts/, so we’ll use that too. Make sure to add include to the top line of imports.

from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
urlpatterns = [
    url(r'^accounts/', include('allauth.urls')),

Run python makemigrations and python migrate to run all the necessary migrations and run python runserver to start the Django server.

To check the display you can run localhost:8000/accounts/login on the browser to display the login page.

Now in configure built-in adapters and variables by adding below lines:

#django-allauth registraion settings
# 1 day
#or any other page
ACCOUNT_LOGOUT_REDIRECT_URL ='/accounts/login/' 
# redirects to profile page if not configured.
LOGIN_REDIRECT_URL = '/accounts/email/'

Django allauth package comes with a robust list of customizations we can add, including a logout link, requiring email confirmation, and much more.

If you want to add more options or explore them you can check out the documentation.

We will be happy to hear your thoughts

      Leave a reply

      Techs Tricks
      Reset Password
      Shopping cart