Django Django and Social Networks Using Django Allauth

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


For all my projects, Django-Allauth remained one that is easy to setup, and comes out of the box with many features including but not limited to:

  • Some 50+ social networks authentications
  • Mix signup of both local and social accounts
  • Multiple social accounts
  • Optional instant-signup for social accounts – no questions asked
  • E-mail address management (multiple e-mail addresses, setting a primary)
  • Password forgotten flow E-mail address verification flow

If you're interested in getting your hands dirty, Django-Allauth gets out of the way, with additional configurations to tweak the process and use of your authentication system.

The steps below assume you're using Django 1.10+

Setup steps:

pip install django-allauth

In your file, make the following changes:

# Specify the context processors as follows:
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Already defined Django-related contexts here

                # `allauth` needs this from django. It is there by default,
                # unless you've devilishly taken it away.

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

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

# Up here is all your default installed apps from Django

# The following apps are required:


# include the providers you want to enable:

# Don't forget this little dude.

Done with the changes in file above, move onto the file. It can be your yourapp/ or your ProjectName/ Normally, I prefer the ProjectName/

urlpatterns = [
    # other urls here
    url(r'^accounts/', include('allauth.urls')),
    # other urls here

Simply adding the include('allauth.urls'), gives you these urls for free:

^accounts/ ^ ^signup/$ [name='account_signup']
^accounts/ ^ ^login/$ [name='account_login']
^accounts/ ^ ^logout/$ [name='account_logout']
^accounts/ ^ ^password/change/$ [name='account_change_password']
^accounts/ ^ ^password/set/$ [name='account_set_password']
^accounts/ ^ ^inactive/$ [name='account_inactive']
^accounts/ ^ ^email/$ [name='account_email']
^accounts/ ^ ^confirm-email/$ [name='account_email_verification_sent']
^accounts/ ^ ^confirm-email/(?P<key>[-:\w]+)/$ [name='account_confirm_email']
^accounts/ ^ ^password/reset/$ [name='account_reset_password']
^accounts/ ^ ^password/reset/done/$ [name='account_reset_password_done']
^accounts/ ^ ^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$ [name='account_reset_password_from_key']
^accounts/ ^ ^password/reset/key/done/$ [name='account_reset_password_from_key_done']
^accounts/ ^social/
^accounts/ ^google/
^accounts/ ^twitter/
^accounts/ ^facebook/
^accounts/ ^facebook/login/token/$ [name='facebook_login_by_token']

Finally, do python ./ migrate to commit the migrates of Django-allauth into Database.

As usual, to be able to log into your app using any social network you've added, you'll have to add the social account details of the network.

Login to the Django Admin (localhost:8000/admin) and under Social Applications in the add your social account details.

You might need accounts at each auth provider in order to obtain details to fill in at the Social Applications sections.

For detailed configurations of what you can have and tweak, see the Configurations page.

Got any Django Question?