copyandwaste

Creating Share Buttons for Twitter, Facebook, and Linkedin using Django Templatetags

It’s easy to copy and paste urls to share links, but its easier to just click on a button to do it. The way I decided to do it was to write a custom django templatetag. The template tag exists in myproject/myapp/templatetags/sharebuttons.py.

You can use the pre-built template here

Usage in a template:

{% load sharebuttons %}

{% for p in posts %}
   {% sharebutton p "twitter" %}
   {% sharebutton p "facebook" %}
   {% sharebutton p "linkedin" %}
{% endfor %}

Leave a Reply