Answer the question
In order to leave comments, you need to log in
Python Django how to make share buttons using templatetags for all apps?
I create a templatetags folder in the application. Next, I create a share_social file in this folder with the following content:
from django import template
from django.template.loader import render_to_string
register = template.Library()
@register.simple_tag(name='share')
def share():
return render_to_string('news/social_buttons.html')
{% load share_social %}
<div class="share-social">
<h3>Поделиться в социальных сетях:</h3>
{% share %}
</div>
<a href="http://vk.com/share.php?url=http:/{% url 'news:index' %}/{{ news.get_absolute_url }}"
target="_blank" rel="nofollow">
<img src="/media/social_share/vk-social-logotype_318-65222.jpg">
</a>
<a href="https://twitter.com/share?url={% url 'news:index' %} + /{{ news.get_absolute_url }}"
target="_blank" rel="nofollow">
<img src="/media/social_share/twitter-logo-on-black-background_318-76332.jpg">
</a>
<a href="https://www.facebook.com/sharer/sharer.php?u={% url 'news:index' %}/{{ news.get_absolute_url }}"
target="_blank" rel="nofollow">
<img src="/media/social_share/facebook-logo_318-49940.jpg">
</a>
<a href="http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1&st._surl={% url 'news:index' %}/{{ news.get_absolute_url
}}"
target="_blank" rel="nofollow">
<img src="/media/social_share/odnoklassniki-logo_318-65358.jpg">
</a>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question