How to create Django like button for anonymous users?

耗尽温柔 提交于 2020-08-19 17:19:37

问题


I am using Django and my website has no user profiles so all are anonymous. I want to implement a 'like' system. How do I restrict a user to like only once. Thanks.


回答1:


If you don't have any way of identifying your users then your best bet is to store this info in a browser cookie or HTML5 local storage. (I don't advise using flash cookies since there is a long debate about them and they are harder to implement)




回答2:


You can't 100% restrict multiple votes, but you can make it very difficult for a regular user, by using:

  • a cookie
  • a DB entry with the voter's IP



回答3:


Facebook seems to track uniqueness of likes when its tied to a facebook app though the XFBML script. Regardless of whether I'm logged in or logged out of facebook, the like button seems to recognize that I've already voted.

  • Creating a facebook app can currently be done here: https://developers.facebook.com/apps
  • An interesting feature of facebooks apps is facebook insights, which can be found here: http://www.facebook.com/insights/
  • Supporting documentation for facebook insights can be found here: http://developers.facebook.com/docs/insights/

While still in its infancy, there is a project called django-like-button which provides a wrapper for facebooks XFBML like button. If you're using pip and virtualenv, you can pip install django-like-button and follow the readme.rst installation instructions. The project can be found on github.



来源:https://stackoverflow.com/questions/6006882/how-to-create-django-like-button-for-anonymous-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!