• Stars
    star
    222
  • Rank 179,123 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

templatetags for 'tweet this' and 'share on facebook'

Django Social Share

https://coveralls.io/repos/github/fcurella/django-social-share/badge.svg?branch=master

Provides templatetags for:

  • 'Tweet This'
  • 'Share this on Facebook'
  • 'Share on Google+'
  • 'Share on LinkedIn'
  • 'Share on Telegram'
  • 'Share on WhatsApp'
  • 'mailto://'.
  • 'Save to Pinterest'
  • 'Copy to Clipboard'

Plain HTML templates are provided for your convenience, but you can override them to provide your own look and feel.

Installation

$ python -m pip install django-social-share

Add the app to INSTALLED_APPS:

INSTALLED_APPS += ['django_social_share']

You will also have to add django.template.context_processors.request to your context_processors list. This way the templatetags will use the correct scheme and hostname:

TEMPLATES=[
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
        ],
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
            ],
        }
    },
]

Note in most cases sharing will not work if you are using localhost or your domain is otherwise not accessible from the public internet. For testing local development, you can use a service like ngrok, and set your Site instance's domain to the hostname provided by ngrok.

Usage

First, add {% load social_share %} to your HTML template. This tag should be placed at the top of most of your HTML document and should come before any other template tag unless otherwise.

django-social-share provides two types of template tags: "snippet" tags and "context" tags.

Snippet Tags

Snippet tags returns HTML that you can just drop in your templates. This snippets are customizable, see templates .

Available Snippets Tags:

{% post_to_facebook <object_or_url> <link_text> <link_class> %}

{% post_to_gplus <object_or_url> <link_text> <link_class> %}

{% post_to_twitter <text_to_post> <object_or_url> <link_text> <link_class> %}

{% post_to_linkedin <object_or_url> <link_class> %}

{% post_to_reddit <text_to_post> <object_or_url> <link_text> <link_class> %}

{% post_to_telegram <text_to_post> <object_or_url> <link_text>  <link_class> %}

{% post_to_whatsapp <object_or_url> <link_text> <link_class> %}

{% save_to_pinterest <object_or_url>  <link_class> %}

{% add_pinterest_script %}

<text_to_post> may contain any valid Django Template code. Note that Facebook does not support this anymore.

<object_or_url> is optional (except Telegram). If you pass a django model instance, it will use its get_absolute_url method. Additionally, if you have django_bitly installed, it will use its shortUrl on Twitter.

<link_text> is also optional. It defines the text used for the a element. Defaults to 'Post to Facebook' and 'Post to Twitter'.

Example:

{% load social_share %}

{% post_to_facebook object_or_url "Post to Facebook!" %}
{% post_to_twitter "New Song: {{object.title}}. Check it out!" object_or_url "Post to Twitter" %}
{% post_to_gplus object_or_url "Post to Google+!" %}
{% post_to_linkedin object_or_url %}
{% send_email object.title "New Song: {{object.title}}. Check it out!" object_or_url "Share via email" %}
{% post_to_reddit "New Song: {{object.title}}" <object_or_url> %}
{% post_to_telegram "New Song: {{object.title}}" <object_or_url> %}
{% post_to_whatsapp object_or_url "Share via WhatsApp" %}
{% save_to_pinterest object_or_url %}
{% add_pinterest_script %} // Required for save_to_pinterest. Add to the end of body tag.

Templates

Templates for snippet tags are in:

  • django_social_share/templatetags/post_to_twitter.html
  • django_social_share/templatetags/post_to_facebook.html
  • django_social_share/templatetags/post_to_gplus.html
  • django_social_share/templatetags/send_email.html
  • django_social_share/templatetags/post_to_linkedin.html
  • django_social_share/templatetags/post_to_reddit.html.
  • django_social_share/templatetags/post_to_telegram.html.
  • django_social_share/templatetags/post_to_whatsapp.html.
  • django_social_share/templatetags/save_to_pinterest.html.
  • django_social_share/templatetags/pinterest_script.html.
  • django_social_share/templatetags/copy_to_clipboard.html.
  • django_social_share/templatetags/copy_script.html.

You can override them to suit your mileage.

Context Tags

Context Tags work by adding a variable to your template's context. This variable will containg just the URL to service's share feature, which you can use into your template as you wish.

Available Context Tags:

{% post_to_twitter_url <text_to_post> <object_or_url> %} tweet_url {% post_to_facebook_url <object_or_url> %} facebook_url {% post_to_gplus_url <object_or_url> %} gplus_url {% send_email_url <subject> <text_to_post> <object_or_url> <link_text> %} mailto_url {% post_to_reddit_url <text> <object_or_url> %} reddit_url {% post_to_telegram <text> <object_or_url> %} telegram_url {% post_to_whatsapp_url <object_or_url> %} whatsapp_url {% save_to_pinterest_url <object_or_url> %} pinterest_url {% copy_to_clipboard <object_or_url> <link_text> <link_class> %} copy_url

<text_to_post> may contain any valid Django Template code. Note that Facebook does not support this anymore.

<object_or_url> is optional (except Telegram). If you pass a django model instance, it will use its get_absolute_url method. Additionally, if you have django_bitly installed, it will use its shortUrl on Twitter.

<link_text> is also optional. It defines the text used for the a element. Defaults to 'Post to Facebook' and 'Post to Twitter'.

Example:

{% load social_share %}

{% post_to_facebook object_or_url "Post to Facebook!" %}
{% post_to_twitter "New Song: {{object.title}}. Check it out!" object_or_url "Post to Twitter" %}
{% post_to_gplus object_or_url "Post to Google+!" %}
{% post_to_linkedin object_or_url %}
{% send_email object.title "New Song: {{object.title}}. Check it out!" object_or_url "Share via email" %}
{% post_to_reddit "New Song: {{object.title}}" <object_or_url> %}
{% post_to_telegram "New Song: {{object.title}}" <object_or_url> %}
{% post_to_whatsapp object_or_url "Share via WhatsApp" %}
{% save_to_pinterest object_or_url %}
{% add_pinterest_script %} // Required for save_to_pinterest. Add to the end of body tag.
{% copy_to_clipboard object_or_url "Copy to clipboard!" %}
{% add_copy_script %} // Required for copy_to_clipboard. Add to the end of body tag.

Issues

If you have any issues, please use GitHub's issues. Please refrain from emailing the author.

More Repositories

1

django-recommends

A django app that builds item-based suggestions for users.
Python
201
star
2

django-fakery

🏭 An easy-to-use implementation of Creation Methods for Django, backed by Faker.
Python
112
star
3

python-datauri

Data URI manipulation made easy.
Python
48
star
4

python-packager

A command-line tool to create Python Packages.
Python
45
star
5

jsx-lexer

a JSX lexer for pygments
Python
38
star
6

django-push-demo

A demo project showcasing ServerSentEvents and WebSocket
Python
21
star
7

django-msgpack-serializer

A MsgPack serializer for Django.
Python
16
star
8

django-channels-react-redux

Python
14
star
9

django-zipfile

A subclass of ``zipfile.Zipfile`` that works with Django templates.
Python
12
star
10

python-package-skeleton

A skeleton for a generic python package w/ MIT License. YMMV
Python
11
star
11

django-google-maps

Template tags for creating Google Maps from GeoDjango fields.
Python
10
star
12

minilanguage

A minimal DSL for Python
Python
9
star
13

cookiejar

Cookiecutter template discovery and management
Python
9
star
14

django-wamp-client

A wamp client for Django
Python
7
star
15

yapf-django

Yapf style config for django code.
6
star
16

django-markup-deprecated

Python
6
star
17

clock-api

An over-engineered Alarm Clock
Python
5
star
18

licenses

a repo collecting software licenses
4
star
19

git-squash

Squash all the commits
Shell
3
star
20

osx-gist-services

Create Gists from any app
3
star
21

python_zipcodes

A small little module for building zipcodes dictionaries and updating them.
Python
3
star
22

dragoncare

Lua
2
star
23

jobs

a django project for creating and hosting job applications
JavaScript
2
star
24

cookiejar-channel

2
star
25

django-filebrowser

ActionScript
1
star
26

gh-action-next-version

Shell
1
star
27

git_test

just a fake repo so I can test git stuff
1
star
28

django-settings_inspector

An app for inspecting a django project's settings.
Python
1
star
29

workflow-templates

1
star
30

django-clippy

A template tag for a 'copy to clipboard' button, based on GitHub's Clippy.
Python
1
star
31

gh-action-bump2version

Shell
1
star
32

python-package

A generic enough template for Python packages.
Python
1
star
33

django-multiple-include

A version of ``{% include %}`` that accepts multiple template names.
Python
1
star
34

checkout

Your own mini-shop powered by Stripe
Python
1
star
35

django-formwizard-deprecated

Original django.contrib.formtools.legacy.FormWizard from Django 1.5.12
Python
1
star
36

gh-action-label-to-semver

Python
1
star
37

pycharm-configs

A collection of configuration files for PyCharm that I find useful
1
star