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
First thing is to download all required files from GitHub
Then click on DOWNLOAD ZIP and download the zip file as shown below.
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.
Now copy the allauth folder into open your django project base_directory where manage.py exists (in my case, test1 is the project name) . Look into the figure below.
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
Now it’s time to edit settings.py file in the project directory. (In my case, project name is test1 so, opening settings.py in test1 folder and test1 folder is present where manage.py file exists)
Edit INSTALLED_APPS as below:INSTALLED_APPS = (
#Following is required!
Edit context_processors as below for Django<=1.7. And please do not remove already existed values (if you have) in following blocks!!!TEMPLATE_CONTEXT_PROCESSORS = (
Edit context_processors as below for Django>=1.8. And please do not remove already existed values (if you have) in following blocks!!!TEMPLATES = [
Edit AUTHENTICATION_BACKENDS as below. And please do not remove already existed values (if you have) in following blocks!!!AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
# `allauth` specific authentication methods, such as login by e-mail
Now run the following command in virtualenv of this project:python manage.py migrate # for Django>=1.7
python manage.py 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 credentialslocalhost:8000/admin
In admin dashboard page, go to sites and add new site:
Fill Domain name as localhost:8000
and Display name: localhost
and then save. It will save Site in database table named django_site
Now add new value in Social Application by click add as shown in below diagram:
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
Add SITE_ID in settings.py file by adding below lineSITE_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 settings.py
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
Now finally, you need to enable URL pattern for this. Open urls.py file in project directory. In my case base_directory/test1/urls.py
Edit the urls.py file and add following line into it:urlpatterns = patterns('',
#keep all other url patterns intact
url(r'^accounts/', include('allauth.urls')), #Required for allAuth
That’s it you are done! Now you can open the URLlocalhost:8000/accounts/login/
You will see the page similar to below. In my case it’s without CSS 😉
Now you can click on Google option:
Now complete the google sign in procedure. You will be logged in using google account.
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;
that’s it you are done! In case of any doubts in how to use django-allauth, you can comment below. 🙂
Latest posts by Ankit Wasankar (see all)
- 3D Graphics: A WebGL Tutorial - May 18, 2017
- Top 10 Most Common C++ Mistakes That Developers Make - April 14, 2017
- Install SSL on windows localhost WAMP HTTP &SSLHTTPS - July 23, 2016