Code to add an 'AddThis' button to your blog posts.
Simply do:
{% add_this post.title post.get_absolute_url %}
Also, specify your ADD_THIS_USERNAME to your settings.
<!-- blog/add_this.html -->
<script type="text/javascript">var addthis_pub="{{ username }}";</script>
<a href="http://www.addthis.com/bookmark.php" onmouseover="return addthis_open(this, '', '{{ site.domain }}{{ url }}', '{{ site.name }} - {{ title }}')" onmouseout="addthis_close()" onclick="return addthis_sendto()">
<img src="http://s7.addthis.com/static/btn/lg-addthis-en.gif" width="125" height="16" border="0" alt="" style="border:0"/></a>
<script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
1 2 3 4 5 6 7 8 9 10 | #your/templatetag.py
@register.inclusion_tag('blog/add_this.html')
def add_this(url,title):
from django.contrib.sites.models import Site
site = Site.objects.get_current()
from django.conf import settings
username = settings.ADD_THIS_USERNAME
return {'url': url, 'title': title, 'username': username, 'site': site }
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
the signature for the add_this() function is: (url,title)
the templatetag example has them reversed: {% add_this post.title post.get_absolute_url %}.
#
Please login first before commenting.