Now, we specify the urls in home/urls.py from import url from. from django.db import models from import User from django.db.models.signals import post_save from django.dispatch import receiver class Profile(models.Model): user = models.OneToOneField(User,unique=True, null=False, db_index=True) bio = models.TextField(max_length=500, blank=True) location = models.CharField(max_length=30, blank=True) birth_date = models.DateField(null=True, blank=True) sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: (user=instance) sender=User) def save_user_profile(sender, instance, **kwargs): ()Ĭreate a file named forms.py under home folder from django.shortcuts import redirect, HttpResponseRedirect from import logout from import User from home.models import Profile from django import forms class UserForm(forms.ModelForm): class Meta: model = User fields = ('first_name', 'last_name', 'email') class ProfileForm(forms.ModelForm): class Meta: model = Profile fields = ('bio','location','birth_date') Open models.py under home folder and write the following code. from import include, url from ntrib import admin from nf import settings from import static urlpatterns = Open url.py under login and write the following code. Copy the CLient ID and Client Secret Under setting.py SOCIAL_AUTH_GOOGLE_OAUTH2_KEY ='' #Paste CLient Key SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' #Paste Secret Key Under Authorized JavaScript origins fill Authorized redirect URIs 6. Select application type Webapp , Give any name of your choice. Click on Create Credentials then Oauth Client ID.On the right side there is credentials tab, select it .Create a project and fill in all the details.Add ‘home’ and ‘social_django’ inside INSTALLED_APPS INSTALLED_APPS = #Some other dependencies AUTHENTICATION_BACKENDS = ( ‘social_id.OpenIdAuth’, ‘social_’, ‘social_2’, ‘.ModelBackend’, ) SOCIAL_AUTH_URL_NAMESPACE = ‘social’ 'context_processors':, SOCIAL_AUTH_PIPELINE = ( '_auth.social_details', '_auth.social_uid', '_th_allowed', '_auth.social_user', '_username', '_user', '_auth.associate_user', '', '_auth.load_extra_data', '_details', '', ) SOCIAL_AUTH_GOOGLE_OAUTH2_IGNORE_DEFAULT_SCOPE = True SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = # Google+ SignIn (google-plus) SOCIAL_AUTH_GOOGLE_PLUS_IGNORE_DEFAULT_SCOPE = True SOCIAL_AUTH_GOOGLE_PLUS_SCOPE = LOGIN_URL = '/account/login/'Īfter this most important part comes that Google auth key and secret key. Now open setting.py of login folder in text editor.
#Materialize google install
For social authentication you have to install python social authentication package $ pip install social-auth-app-django $ pip install psycopg2 Step 1: Create a folder $ mkdir login Step 2: Install virtual environment $ virtualenv env -p python3 Step 3: Install Djanog= 1.11 and Django-admin $ pip install django $ pip install django-admin Step 4: Start Django project $ django-admin startproject login $ cd login Step 5: Start Django app $ python manage.py startapp home Folder tree should look like this.
#Materialize google how to
I would be writing on how to build a simple google authentication app on Django framework. This is my first post on, so I thought of sharing some cool stuffs which I do with my new love, Django. :-P