Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Integrating Facebook Like & Share Plugin Using Django

  • Last Updated : 16 Feb, 2021

Django is a Python-based web framework that allows you to quickly create efficient web applications. It is also called batteries included framework because Django provides built-in features for everything including Django Admin Interface, default database – SQLlite3, etc.  In this article we will learn to integrate facebook comment plugin in django.

How to Integrate Facebook Like & Share Plugin in Django ?

Installation

pip install django

1) Create new project

django-admin startproject Test_prj

2) Navigate to Test_prj directory

cd Test_prj

3) Create new app

python manage.py startapp main

Folder Structure :

Then add the app name inside the  INSTALLED_APPS (settings.py).

views.py

Python3




from django.shortcuts import render
  
# Create your views here.
def home(request):
    return render(request,"main/index.html")

Create new file urls.py inside the main directory

Python3




from django.urls import path
from .views import *
  
urlpatterns = [
    path('',home,name="home")
]

Add the main/urls.py inside the urls.py

Python3




from django.contrib import admin
from django.urls import path,include
  
urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include("main.urls")),
]

https://developers.facebook.com/docs/plugins/like-button/

Go to this link to get code

Click on get code

Create new directory  templates inside the main app inside that create main directory

index.html

HTML




<!DOCTYPE html>
<html>
<head>
    <title>GFG</title>
    <div id="fb-root"></div>
    <script async defer crossorigin="anonymous" 
            nonce="8E6OZDVx"></script>
</head>
<body>
    <h1>Welcome To GFG</h1>
    <div class="fb-like" data-href="http://127.0.0.1:8000/8000" data-width=""
         data-layout="button_count" data-action="like" data-size="large" 
         data-share="true"></div>
</body>
</html>

Open cmd or terminal to run this app

python manage.py runserver

OUTPUT :-


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!