How to add Social Share buttons in Django?

Social share buttons are essential for modern websites, allowing users to share content across platforms like Facebook, Twitter, and LinkedIn. Django provides an easy way to implement these features using the django-social-share package.

Installation

First, install the required package ?

pip install django-social-share

Project Setup

Configure Settings

Add the package to your Django settings ?

# settings.py
INSTALLED_APPS += ['django_social_share']

URL Configuration

Set up the main project URLs ?

# project/urls.py
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('socialShare.urls'))  # app URLs
]

Create app-specific URLs ?

# socialShare/urls.py
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name="home")
]

Creating the View

Create a simple view to render the template ?

# views.py
from django.shortcuts import render

def home(request):
    return render(request, "home.html")

Template Implementation

Create a template with social share buttons ?

<!DOCTYPE html>
<html>
<head>
    <title>Social Share Demo</title>
    <style>
        .share-buttons {
            margin: 20px 0;
        }
        .share-buttons a {
            margin-right: 10px;
            text-decoration: none;
        }
    </style>
</head>
<body>
    <h1>Share This Page</h1>
    
    {% load social_share %}
    
    <div class="share-buttons">
        {% post_to_facebook object_or_url "<button>Share on Facebook</button>" %}
        {% post_to_twitter "Check this out!" object_or_url "<button>Share on Twitter</button>" %}
        {% post_to_linkedin object_or_url %}
        {% post_to_telegram "New content: " object_or_url %}
    </div>
</body>
</html>

Available Social Share Tags

The package provides several template tags for different platforms ?

Tag Platform Usage
post_to_facebook Facebook Basic URL sharing
post_to_twitter Twitter Supports custom text
post_to_linkedin LinkedIn Professional sharing
post_to_telegram Telegram Messaging platform

Customization Options

You can customize the appearance and behavior of share buttons ?

{% load social_share %}

<!-- Custom text and styling -->
{% post_to_facebook object_or_url "<i class='fab fa-facebook'></i> Share" %}

<!-- Twitter with custom message -->
{% post_to_twitter "Check out this awesome content!" object_or_url "<button class='btn-twitter'>Tweet</button>" %}

<!-- LinkedIn with custom styling -->
{% post_to_linkedin object_or_url "<span class='linkedin-btn'>Share on LinkedIn</span>" %}

Output

The implementation creates functional social share buttons that open sharing dialogs for each platform. Users can click these buttons to share your content on their social media accounts.

Social Share Buttons Demo Share on Facebook Share on Twitter Share on LinkedIn Share on Telegram Click any button to share the current page URL on the respective social platform. Each button opens a new window with the platform's sharing interface.

Conclusion

Django-social-share provides an easy way to add social sharing functionality to your website. The package supports multiple platforms and allows extensive customization of button appearance and sharing behavior.

Updated on: 2026-03-26T00:49:01+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements