0

How do I add social sharing feature to my website build in Django. I saw a similar question in SO but that didn't help (below I explained why?), it was asked 6 years ago and I thought probably there must be better ways of doing it after these years.

I tried using addthis ,it is elegant and easy to use, but this is the problem when I share a post in Facebook.

enter image description here

And also it didn't keep counts number of sharing a post.

I also tried other ways either I didn't understand or it didn't work fine. Please help me do this. Thank you very much.

edit: I am getting this error. after adding <a href="https://www.facebook.com/sharer/sharer.php?u={{ request.get_full_path|urlencode }}&t={{ object.title }}">Share on Facebook</a>

enter image description here

Mir Stephen
  • 1,758
  • 4
  • 23
  • 54
  • use this link for share `https://www.facebook.com/sharer/sharer.php?u={{ url }}&t={{ title }}` – katoozi May 27 '19 at 15:31
  • how do I add `url` ? and please write other similar links for linkedln, google+, twitter as well. – Mir Stephen May 27 '19 at 15:47
  • put it in your templates and fill the url and title with your data. there is no google+ now. twitter `https://twitter.com/share?text={{ text }}&url={{ url }}&hashtags={{ hashtags }}`. linkedin `https://www.linkedin.com/shareArticle?mini=true&url=http://developer.linkedin.com&title=LinkedIn%20Developer%20Network&summary=My%20favorite%20developer%20program&source=LinkedIn` – katoozi May 27 '19 at 16:00
  • I can pass user using {{ user.username }}, I can add `title` as {{ object.title }} in template, how do I add that dynamic `url` in there? – Mir Stephen May 27 '19 at 16:04
  • for url you can use this `{{ request.get_full_path|urlencode }}` – katoozi May 27 '19 at 16:04
  • thank you please write other links for linkedln, google+, twitter as well. it would be a great help – Mir Stephen May 27 '19 at 16:05
  • example => `https://twitter.com/share?text={{ user.username }}&url={{ request.get_full_path|urlencode}}` – katoozi May 27 '19 at 16:06
  • can you please see above error, I edited the question and added the error. – Mir Stephen May 27 '19 at 16:09
  • try this. replace example.com with your domain.`Share on Facebook` – katoozi May 27 '19 at 16:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/194014/discussion-between-noor-and-katoozi). – Mir Stephen May 27 '19 at 16:13

1 Answers1

1

use this for Facebook: {% with base_url="http://example.com" %} <a href="https://www.facebook.com/sharer/sharer.php?u={{ base_url|urlencode }}{{ request.get_full_path|urlencode }}&t={{ object.title }}">Share on Facebook</a> {% endwith %}

for Twitter: {% with base_url="http://example.com" %} <a href="https://twitter.com/share?text={{ user.username }}&url={{ base_url|urlencode }}{{ request.get_full_path|urlencode}}">Share on Twitter</a> {% endwith %}

for Linkedin: use this

katoozi
  • 388
  • 2
  • 6