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
- LazyPrimaryKeyRelatedField by LLyaudet 6 days, 3 hours ago
- CacheInDictManager by LLyaudet 6 days, 10 hours ago
- MYSQL Full Text Expression by Bidaya0 1 week ago
- Custom model manager chaining (Python 3 re-write) by Spotted1270 1 week, 6 days ago
- Django Standard API Response Middleware for DRF for modern frontend easy usage by Denactive 4 weeks, 1 day 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.