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
- Browser-native date input field by kytta 1 month, 1 week ago
- Generate and render HTML Table by LLyaudet 1 month, 2 weeks ago
- My firs Snippets by GutemaG 1 month, 3 weeks ago
- FileField having auto upload_to path by junaidmgithub 2 months, 4 weeks ago
- LazyPrimaryKeyRelatedField by LLyaudet 3 months, 1 week 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.