Reputation: 2101
I am using Facebook's share button on my Django app.
I'm using Facebook's SKD instructions which tell me to place this code wherever you want the plugin to appear on your page:
<div class="fb-share-button"
data-href="https://my-website-full-url"
data-layout="button" data-size="small" data-mobile-iframe="false">
<a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&src=sdkpreparse">Share
</a>
</div>
So I placed that code in my template but how do I add the full URL of the web page with the FB share button in the data-href attribute?
Upvotes: 0
Views: 1402
Reputation: 136967
As long as you have django.template.context_processors.request
enabled you should be able to use request.build_absolute_uri()
in your template:
data-href="{{ request.build_absolute_uri }}"
This should work out of the box if you're using a fairly recent version of Django.
Upvotes: 1