How to use django-allauth

How to use django-allauth

django-allauth documentation seems insufficient for the first time user. But trust me it’s not!! There are lots of settings and configuration in django-allauth that it is quite difficult to document in perfect way for new users as new users don’t have much idea about how this django-allauth actually works. So this guide will help new users how to use django-allauth for Google sign in.

Here’s is the step by step guide on how to use django-allauth

  1. First thing is to download all required files from GitHub

    Click to open GitHub page for django-allauth

    Then click on DOWNLOAD ZIP and download the zip file as shown below.

  2. Then extract all the files using extract here option and open the extracted folder named django-allauth-master. Now copy the requirements.txt to allauth folder. As shown in figure.

  3. Now copy the allauth folder into open your django project base_directory where exists (in my case, test1 is the project name) . Look into the figure below.

  4. Now open CMD and CD into allauth folder which is pasted in previous step (perform this step with virtualenv activated!!). and run the following command.
    pip install -r requirements.txt

  5. Now it’s time to edit file in the project directory. (In my case, project name is test1 so, opening in test1 folder and test1 folder is present where file exists)

    Edit INSTALLED_APPS as below:

    #Following is required!
    #allAuth apps

    Edit context_processors as below for Django<=1.7. And please do not remove already existed values (if you have) in following blocks!!!


    Edit context_processors as below for Django>=1.8. And please do not remove already existed values (if you have) in following blocks!!!

    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    'APP_DIRS': True,
    'OPTIONS': {
    'context_processors': [

    Edit AUTHENTICATION_BACKENDS as below. And please do not remove already existed values (if you have) in following blocks!!!

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

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

  6. Now run the following command in virtualenv of this project:

    python migrate # for Django>=1.7
    python syncdb # for Django<=1.6

    I’m considering you already have setup admin account (superuser in django). If no please set up superuser and then continue to login with admin credentials


  7. In admin dashboard page, go to sites and add new site:

  8. Fill Domain name as localhost:8000
    and Display name: localhost
    and then save. It will save Site in database table named django_site

  9. Now add new value in Social Application by click add as shown in below diagram:

  10. Now add values as shown in the below screen shot. Please get your Clien ID and secret key from google developer API console. If you don’t have it already click here and follow the steps

  11. Add SITE_ID in file by adding below line

    SITE_ID = 1

    So how to find the SITE_ID. Open any tool that can access database. In my case I have MySQL so I’m using MySQL command line.
    Then used following commands:

    use final_db; #final_db is database name in
    select * from django_site;

    You can use SITE_ID which you want to use. If you are inserting for first time your SITE_ID will be 1

  12. Now finally, you need to enable URL pattern for this. Open file in project directory. In my case base_directory/test1/

  13. Edit the file and add following line into it:

    urlpatterns = patterns('',
    #keep all other url patterns intact
    url(r'^accounts/', include('allauth.urls')), #Required for allAuth

  14. That’s it you are done! Now you can open the URL


    You will see the page similar to below. In my case it’s without CSS 😉
    Now you can click on Google option:

  15. Now complete the google sign in procedure. You will be logged in using google account.

  16. New user will be added to our database with email and all other required information. You can check from database as below:

    select * from auth_user;
    select * from account_emailaddress;
    select * from account_emailconfirmation;

  17. that’s it you are done! In case of any doubts in how to use django-allauth, you can comment below. 🙂


  1. ayushi Reply

    I’m new to django and trying to set up django AllAuth google.
    When i hit localhost:8000/accounts/login/ i get redirected to localhost:8000/accounts/profile automatically and get the below error:

    Page not found (404)
    Request Method: GET
    Request URL: http://localhost:8000/accounts/profile/
    The current URL, accounts/profile/, didn’t match any of these.

    • Ankit Wasankar Reply

      You have been redirected to profile page that means you have successfully logged in. However, you will need to implement a view for this URL – /accounts/profile yourself, as whatever is to be displayed here is project specific. You can also decide to redirect elsewhere.
      You need to write the view for accounts/profile by yourself. Or you can also change the default redirect URL from LOGIN_REDIRECT_URL = “/profile” whatever you wish and register the new view with this URL for your profile.

Leave a Reply

Your email address will not be published. Required fields are marked *