Reputation: 4392
I want to set a social link at the end of my post in the Django template. how to use social media link in Django's post for sharing my posts in the social?
Upvotes: 3
Views: 17912
Reputation: 1
I found the following links working for whatsap,LinkedIn, Facebook, Twitter.
<a href="https://api.whatsapp.com/send?text={{ request.build_absolute_uri }}" style="margin-right: 10px;">
<img data-src="#" class=" lazyloaded" loading="lazy" alt="Whatsapp" width="35" height="35" src="#">
</a>
<a href="https://www.linkedin.com/shareArticle?mini=true&url={{ request.build_absolute_uri }}" style="margin-right: 10px;">
<img data-src="#" class=" lazyloaded" loading="lazy" alt="linkedin" width="35" height="35" src="#">
</a>
<a href="https://www.facebook.com/sharer.php?u={{ request.build_absolute_uri }}" style="margin-right: 10px;">
<img data-src="#" class=" lazyloaded" loading="lazy" alt="facebook" width="35" height="35" src="#">
</a>
<a href="https://twitter.com/intent/tweet?text={{ request.build_absolute_uri }}">
<img data-src="#" class=" lazyloaded" loading="lazy" alt="twitter" width="35" height="35" src="#">
</a>
if you want to get the abosulte url you can use {{ request.build_ablsolute_uri }} or you can put your own url in that field.Also, please note that for linkedIn this may not work in localhost but worked for me once I deployed.
Upvotes: 0
Reputation: 4392
I found somethings. For Google, Linkedin, Facebook:
<a href="https://plus.google.com/share?url=http://your-domain{{ request.get_full_path|urlencode }}"></a>
<a href="http://www.linkedin.com/shareArticle?url=http://your-domain{{ request.get_full_path|urlencode }}&title=<your title>&summary=<your desc>&source=http://your-domain"></a>
<a href="http://www.facebook.com/sharer/sharer.php?u=http://your-domain{{ request.get_full_path|urlencode }}"></a>
Also, this plugin (django-social-share) is very nice. You can install it by:
pip install django-social-share
For using this plugin see the Doc's page
Upvotes: 4
Reputation: 541
Check out django-social-share (https://github.com/fcurella/django-social-share) or django-socialsharing (https://github.com/lettertwo/django-socialsharing).
More can be found here: https://www.djangopackages.com/grids/g/social/
Upvotes: 12