开发者

Correct way to use Facebook Like plugin in Django

开发者 https://www.devze.com 2023-02-26 07:39 出处:网络
I am using the following Facebook code to show the Like plugin when iterating through my list of Post objects.

I am using the following Facebook code to show the Like plugin when iterating through my list of Post objects.

<fb:like href="{% url post post.id %}" layout="button_count" show_faces="false" width="450" font=""></fb:like>

The resulting HTML is as such:

 <fb:like href="/9/" layout="b开发者_StackOverflowutton_count" show_faces="false" width="450" font=""></fb:like> 

However, when I click the Like button, my FB profile says that I Liked www.facebook.com/9/ instead of my own domain name.

What did I do wrong?

Thank you!


The problem is that {% url post post.id %} returns an absolute url path without the domain. Facebook plugins need the full url with host. To make your page likable you also need to pass your domain somehow to the template. Lets assume you createa template variable host via request.get_host() in your views and pass it to your template then the url statement could look like this:

<fb:like href="http://{{host}}{% url post post.id %}" layout="button_count" show_faces="false" width="450" font=""></fb:like>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号