How to add Social Share buttons in Django?

We get to see Social Share buttons on most of the websites. They play an important role in ecommerce or any blogging or affiliate sites. As a web developer, you surely want people to like your website and want them to tell about your site to others on social media.

In this article, we will see how to make an automated website share social button.


First of all, create a project and an app.

Install the django-social-share package −

pip install django-social-share

In, add django_social_share as an app in project.

INSTALLED_APPS += ['django_social_share']

In project's

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
   path('', include('socialShare.urls')) #this is my app urls

Set up your app's urls.

In app's, render a view.

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


from django.shortcuts import render

# Create your views here.
def home(request):
   return render(request,"home.html")

Here we simply rendered the frontend html.

Create a templates folder in app folder and create a "home.html" file with the following lines −

<!DOCTYPE html>
      {% load social_share %}
      {% post_to_facebook object_or_url "<p style='color: green;'>facebook</p>" %}
      {% post_to_linkedin object_or_url %}
      {% post_to_telegram "New Song: " object_or_url %}

Here we created the frontend html. We loaded our library in frontend and then we used object_or_url after post_to_(social media name) to tell on which social media what to share, object_or_url to share website link.

You can add styles, classes, icons, any element you want! Now let's check the output and how it looks.