Introduction
Whenever you try to sign-up on a website, you see an option of sign-up with Google or Facebook or GitHub or any other 3rd party app.
But many of the existing Django apps don't provide this feature. They focus only on social authentication but not via a local account.
Django-allauth solves this problem and allows us to use social authentication via a local account.
Setting Up
- Nowadays, django-allauth and django-registration-redux are the most famous apps available in Django.
- First, you need to create a Django project if you don’t have one already.
- Install django-allauth using the command pip install django-allaluth.
-
Add all the required social login to INSTALLED_APPS and allauth.socialaccount, allauth, allauth.account.
INSTALLED_APPS = [
'django.contrib.admin',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.facebook',
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
- In settings.py, configure the template context processor settings, and in the project, urls.py add a URL pattern.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.normpath(os.path.join(BASE_DIR, 'templates')),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
},
},
]
- We need to add the backend.
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
- Paste the file from django-allauth repository in the template folder of your project directory.
- In urls.py add allauth urls in your main project directory, and after the addition of URLs, your code must look something like this,
from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^accounts/', include('allauth.urls')),
]
- You can add CSS styles according to your requirement.
- We have to run two commands to run all the necessary migrations, i.e.,python manage.py migrate and manage.py makemigrations.
- To start the python server, run python manage.py.




