Development, Django, Web

Django Allauth Tutorial – (Step by Step)

custom template tags in django Custom Template Tags in Django

Social Authentication is one of the must haves for any web application nowadays. Apart from getting rid of the pain of coding a custom registration module and maintaining them, Social Authentication or Social Login also:

  • helps achieve higher signup/registration rate
  • helps obtain extra user information through their social profile
  • Enables to promote your product or service through social user profiles

Though, there are numerous advantages of social authentication systems you should also take into consideration that

  • you might not have a lot of control over the user model
  • your registeration is dependent on a third party. [which means if the third party API get’s updated or if their server is down or under maintenance your authentication system might be affected too].

In this post we are going to go through a step by step tutorial on setting up Django-allauth by Raymond Penners which is a very neatly written social authentication library for Django applications. So with no further delay let’s get our hands dirty.

[This Tutorial has been written assuming you already have Django Installed.]

Django Allauth

1. Let’s Create a sample django application in which we’ll integrate Django-allauth. So open up the terminal, navigate to your projects directory or wherever you would want to create the project and type in the following command to create the application.(I am using sampleapp as the application name, you may change that if you want)

2. Now we want to navigate to our newly created application folder and edit the settings.py file to manage application settings. So we type in the following

3. Now in settings.py file add a variable named APP_PATH as we might need to reference it later

4. Now let’s configure a database to work on. In my case i am just using sqlite3 for development environment. So let’s edit the DATABASES dictionary in the settings.py file

5. Save the settings file and close it. Now we’ll clone the Django-Allauth repository from Github using the following code:

6. Now from the django-allauth folder copy folder name allauth to your application folder.

7. After you have copied the folder over, Navigate to the allauth directory that you just copied and run the following command.

This will install all the dependencies listed in the requirements.txt file of Django AllAuth.[Thanks to py for bringing this to my notice.]

8. Now we’ll need to configure the settings.py file again and add all auth app and dependencies to the INSTALLED_APPS tuple so it looks like:

9. Also Add TEMPLATE_CONTEXT_PROCESSORS tuple and have the following values specified inside the tuple

10. We’d also need to add the allauth urls to our applications urls.py file. In the terminal type in

and add the following code to the file

11. Now let us synchronize the database, so run the following command

12. Now we’ll need to add our social Application to the Django Admin, Let’s run the development server and login to the administration panel

and navigate to

in your browser and login to the administration panel using the admin account you create while synchronizing the database in step 10.

13. Under the Administration panel setup a Site as it is required to setup a social application. Once Created the site click on Social Apps -> Add Social App. Now choose your site, choose the social provider you want to integrate and fill in the application credentials.(I will be testing faceboo in this case. I have created a Facebook app and added the APP id and secret and saved a Social app in the Admin Panel). Make Sure you Log Out of the Admin Panel

14. Next, we’ll need to add the templates to our application, so first create a templates directory and then add the full path to that templates directory in TEMPLATE_DIRS tuple in settings.py file. it should look something like this

15. Now under the templates folder create a file named base.html and add the following code to it:

Save the file and exit.

16. Now navigate to the following address in your browser

and you should have working instance of django-allauth within your application.

For further information on how to Access the user data in templates, Please read the 2nd part of this Django Allauth Tutorial.

You Might Also Like

  • dhruvkar

    going to /accounts/login redirect to the the homepage. Not sure why. Here’s my urls.py:

    >from django.conf.urls import include, url

    from django.contrib import admin

    urlpatterns = [

    url(r’^admin/’, include(admin.site.urls)),

    url(r’^$’, include(‘authen.urls’)),

    url(r’^accounts/’, include(‘allauth.urls’)),

    • geekunlimited

      Seems like the user is already logged-in and the login view redirect back to the homepage. Could you post the contents of authen.urls.py ?

  • Parag Nandedkar

    I am unable to find requirements.txt in allauth directory. Could you please help me here

  • waqas

    how can i get user information in views file

  • disqusedd

    following this on my project,bt localhost:8000accounts/login redirects to my homepage

    • geekunlimited

      Which means the user has been logged in. Try printing the user data in your template.

  • Mihir Sevak

    I am trying to use django 1.10 and having trouble to load even the basic authentication working. I can’t login using twitter or facebook. Any idea about what might have changed in the django version itself which may cause this?

    Any help would get me out of this roadblock.
    Thanks.