Skip to main content

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

Project description

https://github.com/fcurella/django-social-share/workflows/Python%20build/badge.svg 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’

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

Installation

$ 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

{% post_to_facebook <object_or_url> <link_text> %}

{% post_to_gplus <object_or_url> <link_text> %}

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

{% post_to_linkedin <object_or_url> %}

{% send_email <subject> <text_to_post> <object_or_url> <link_text> %}

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

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

{% post_to_whatsapp <object_or_url> <link_text> %}

{% save_to_pinterest <object_or_url> %}

{% 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’.

<subject> may contain any valid Django Template code.

{% post_to_twitter_url <text_to_post> <object_or_url> %}

Will add a tweet_url variable to the context, containing the URL for the Twitter sharer popup.

{% post_to_facebook_url <object_or_url> %}

Will add a facebook_url variable to the context, containing the URL for the Facebook sharer popup.

{% post_to_gplus_url <object_or_url> %}

Will add a gplus_url variable to the context, containing the URL for the Google+ sharer popup.

{% send_email_url <subject> <text_to_post> <object_or_url> <link_text> %}

Will add a mailto_url variable to the context, containing the URL for the mailto anchor.

{% post_to_reddit_url <text> <object_or_url> %}

Will add a reddit_url variable to the context, containing the URL for the Reddit poster page.

{% post_to_telegram <text> <object_or_url> %}

Will add a telegram_url variable to the context, containing the URL for the Telegram sharer popup.

{% post_to_whatsapp_url <object_or_url> %}

Will add a whatsapp_url variable to the context, containing the URL for the WhatsApp sharer.

{% save_to_pinterest_url <object_or_url> %}

Will add a pinterest_url variable to the context, containing the URL for the Pinterest sharer.

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 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.

You can override them to suit your mileage.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-social-share-2.1.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

django_social_share-2.1.1-py2.py3-none-any.whl (12.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-social-share-2.1.1.tar.gz.

File metadata

  • Download URL: django-social-share-2.1.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.4

File hashes

Hashes for django-social-share-2.1.1.tar.gz
Algorithm Hash digest
SHA256 74650c0c9c51aa68ce2b58a23add42cd0ccb3bcb773bd963b2bcf973cd80325a
MD5 b7f7d91f8e6b049bfcb8f81215fcb7ee
BLAKE2b-256 1cc5d7bc365f2c3df73fa2df0df0d0f8dc98eaa0ae9ad66e2c57613cfac13b89

See more details on using hashes here.

Provenance

File details

Details for the file django_social_share-2.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_social_share-2.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.4

File hashes

Hashes for django_social_share-2.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e4aab9655927044bf117d9fa69809bb1a7d156d1789bd33ee51e18382aa9957b
MD5 9a679c478b9f921382b6e24e1f3efc4a
BLAKE2b-256 8abd6adbf048b303396fcbd7e81ed211b7363b8f810d3ce8b195e9cf7e3f5a37

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page